Solved

C# App not working in Windows 2000

Posted on 2009-07-13
8
194 Views
Last Modified: 2013-12-17
I have an application written in C# using Microsoft Visual Studio 2005 Professional Edition Version 8.0.50727.762 (SP.050727-7600) AND Microsft .NET Framework Version 2.0.50727 SP1.

The app works on all the XP and Vista Machines but not on the 2000 Machines. Unfortunately upgrading the OS is not an option right now.
============
Microsoft Windows 2000
5.00.2195
Service Pack 4
============

When starting the application it prompts the user to scan there user id. On Return button click I get this error: (SEE Attached Text file "DEBUG.txt").

I can see that there is a problem where the app tries to access the database. (SEE Coded text below for my ODBC connection).

Are there any specific configurations that must be setup for the 2000 Machines?

Thanks any help here would be appreciated.
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;
 

namespace ShippingTrackingSystem

{

    class clsMySqlODBCConnection

    {

        public int QueryType = 0;

        public System.Data.Odbc.OdbcConnection OdbcCon;

        public System.Data.Odbc.OdbcCommand OdbcCom;

        public System.Data.Odbc.OdbcDataReader OdbcDR;

        public string ConStr;

        //

        private string MySqlServer = "MydbServer";

        private string MySqlPort = "MydbPort";

        private string MySqlDatabase = "MydbName";

        private string MySqlUser = "MydbUser";

        private string MySqlUserPass = "MydbPass";

        private string MySqlOption = "MydbOption";

        //

        public clsMySqlODBCConnection()

        {

            ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + MySqlServer + ";PORT=" + MySqlPort + ";DATABASE=" + MySqlDatabase + ";UID=" + MySqlUser + ";PWD=" + MySqlUserPass + ";OPTION=" + MySqlOption + "";

            OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);
 

            try

            {

                //txtLog.AppendText("Openning connection...\r\n");

                if (OdbcCon.State == ConnectionState.Closed)

                {

                    OdbcCon.Open();

                }

                //txtLog.AppendText("Connection opened\r\n");

                //MessageBox.Show("Connection opened\r\n");

            }

            catch (System.Data.Odbc.OdbcException Ex)

            {

                //txtLog.AppendText(Ex.Message + "\r\n");

                //MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try again.\r\n\r\nMore details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

        }

        public void MySqlDisconnection()

        {

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCon.Close();

                //MessageBox.Show("Connected Closed\r\n");

            }

        }

        public void ShowTables()

        {

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCom = new System.Data.Odbc.OdbcCommand("SHOW TABLES", OdbcCon);

                OdbcDR = OdbcCom.ExecuteReader();

                //txtLog.AppendText("Tables inside " + txtDatabase.Text + ":\r\n");

                while (OdbcDR.Read())

                {

                    //txtLog.AppendText(">> " + OdbcDR[0] + "\r\n");

                }

            }

        }

        public string[] MySQLQuery(string qry, int fldidx)

        {

            List<string> list = new List<string>();
 

            string tStr = null;     // the following is not needed: = Convert.ToString(null);

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCom = new System.Data.Odbc.OdbcCommand(qry, OdbcCon);

                if (fldidx >= 0)

                {

                    OdbcDR = OdbcCom.ExecuteReader();

                    while (OdbcDR.Read())

                    {

                        tStr = Convert.ToString(OdbcDR[fldidx]);

                        list.Add(tStr);

                    }

                }

                else

                {

                    OdbcCom.ExecuteNonQuery();

                    QueryType = 1;

                }

            }

            return list.ToArray();

        }
 

        public IDataReader MySQLQuery(string qry)

        {

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCom = new System.Data.Odbc.OdbcCommand(qry, OdbcCon);

                OdbcDR = OdbcCom.ExecuteReader();

            }

            return OdbcDR;

        }
 

        public void MySQLNONQuery(string qry)

        {

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCom = new System.Data.Odbc.OdbcCommand(qry, OdbcCon);

                OdbcCom.ExecuteNonQuery();

                QueryType = 1;

            }

        }
 

        public object InitializeCnnObject()

        {

            // Create and initilize a recordset to represent the User Table

            clsMySqlODBCConnection OpenConnection = new clsMySqlODBCConnection();

            return OpenConnection;

        }

    }

}

Open in new window

DEBUG.txt
0
Comment
Question by:SaltyDawg
8 Comments
 
LVL 18

Assisted Solution

by:UnifiedIS
UnifiedIS earned 125 total points
ID: 24841119
Try updating MDAC (microsoft data access components)
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 24841375
MDAC version should not be the problem when using ODBC drivers. However, there is no other clue at the moment, and updating to MDAC 2.8 does not hurt.

You did not show the calling method
ShippingTrackingSystem.clsEbtronUser.ValidateUser(String user)
, but I reckon it is calling InitializeCnnObject(). The method seems to return a NULL pointer, probably because you are catching ODBC errors, but not executing any error fallback code in case of connection failure. If you would at least output the error message, it might help.
0
 
LVL 1

Author Comment

by:SaltyDawg
ID: 24841456

        private void cmdEnter_Click(object sender, EventArgs e)

        {

            clsShippingTrackingSystem TrackingSystem = new clsShippingTrackingSystem();

            clsEbtronUser EbtronUser = new clsEbtronUser();
 

            ScanUserID = txtScanUserId.Text;

            TrackingSystem.SetUserString(ScanUserID);
 

            UserString = TrackingSystem.GetUserString();

            UserAccess = EbtronUser.ValidateUser(UserString);
 

            if (!UserAccess)

            {

                lblUserValidated.Text = "User Not Validated";

            }

            else

            {

                frmUserID.ActiveForm.Close();

            }

        }

        public bool ValidateUser(string user)

        {

            clsMySqlODBCConnection OpenConnection = new clsMySqlODBCConnection();

            clsShippingTrackingSystem TrackingSystem = new clsShippingTrackingSystem();

            //

            string UserID = null;

            string PermissionLevel = null;

            string strQry = "Select User.Id, Program_Permissions.Permission_Level FROM User, Program_Permissions WHERE User.UserString = '" + user + "' AND Program_Permissions.Id = User.Id AND Program_Permissions.Program_Id = '" + Convert.ToString(TrackingSystem.GetProgramID()) + "' LIMIT 0, 1";

            //

            OpenConnection.MySQLQuery(strQry);

            while (OpenConnection.OdbcDR.Read())

            {

                UserID = Convert.ToString(OpenConnection.OdbcDR["Id"]);

                PermissionLevel = Convert.ToString(OpenConnection.OdbcDR["Permission_Level"]);

                TrackingSystem.SetUserID(UserID);

                TrackingSystem.SetUserPermission(PermissionLevel);
 

                OpenConnection.MySqlDisconnection();

                return true;

            }

            OpenConnection.MySqlDisconnection();

            return false;

        }

Open in new window

0
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 125 total points
ID: 24842199
I'm willing to bet that one of these objects is NULL

TrackingSystem.GetProgramID()
OpenConnection.OdbcDR["Id"]
OpenConnection.OdbcDR["Permission_Level"]

I would recommend executing the SQL you *THINK* is being executed against the DB and making sure that there is a non-NULL value in "Id" and "Permission_Level". If either value is NULL, *THAT* is your problem. If neither is NULL, then the .GetProgramID() is probably returning a NULL.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:SaltyDawg
ID: 24843390
I checked everything. All my variables have the correct data including my query string. It seems to fail at: OpenConnection.MySQLQuery(strQry);

Again everything seems to work fine on XP and Vista so that's why I summized it being an issue with 2000. I am not sure if it's an configuration problem in 2000 or with the ODBC configuration or a .NET problem in 2000. Currently .NET version 2.0.50727 is installed
0
 
LVL 1

Author Comment

by:SaltyDawg
ID: 24860036
I found the issue. It was the ODBC. Turns out I did need the MySQL Connector/ODBC updated drivers for Win2000/NT. These were installed and now everything works.

Thanks
0
 
LVL 1

Author Comment

by:SaltyDawg
ID: 24860072
in the statement:
if (OdbcCon.State == ConnectionState.Open)

OdbcCon.State  was closed therefore returning a NULL to OdbcDR.

Thanks for all your help
        public IDataReader MySQLQuery(string qry)

        {

            if (OdbcCon.State == ConnectionState.Open)

            {

                OdbcCom = new System.Data.Odbc.OdbcCommand(qry, OdbcCon);

                OdbcDR = OdbcCom.ExecuteReader();

            }

            return OdbcDR;

        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:SaltyDawg
ID: 31602893
Thanks. I split the points but since Qlemo was closer and his post actually led me to coming to the solution I gave him more.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now