Connection Problem with MySQL and ByteFX

grip003

Well-known member
Joined
Sep 2, 2004
Messages
89
Location
North Carolina
I am writing my own GUI front end for MySQL using C# and the ByteFX libraries. When the user wants to open a database, it asks for the server, port #, database, user name, and password to connect to MySQL. I have a test function that looks like the following:

Code:
public bool testConnection(string server, string port,
			string d_base, string user, string password)
{
     string con_str = "Data Source=" + server + 
          ";Port=" + port + ";Database=" + d_base +
          ";User ID=" + user + ";Password=" +
          password + "";

     MySqlConnection mysql_conn =  new MySqlConnection(con_str);
     try
     {
          mysql_conn.Open();
	  mysql_conn.Close();
	  return true;
     }
     catch (Exception)
     {
          mysql_conn.Dispose();	
	  return false;
     }
}
If I put the correct informtion in the FIRST time, this function returns true. However, if I put in some incorrect information the first time (which returns false) but then correct the information and try it again, it returns false. Actually it returns false everytime after the initial wrong entry. The exception I get is
Access denied for user ...@...
Is this a MySQL issue or a programming issue? I cant seem to get this to work.
 
Small Addition

I just tried something else and it really confused me. I tried entering the correct information, which worked. Then I went back and tried entering wrong information, and that returned true!! So, whatever I enter the first time seems to stay in the connection somehow. Any ideas?
 
Seems to be an issue with ConnectionPooling.
Try to dispose() the connection everytime.
 
Are you using hte ByteFX 0.76 library? If so, Id recommend that you upgrade to the MySql Connector.Net 1.0.5 found on the MySql web site.

Its essentially that same codebase, but 1.0.5 has been greatly extended since Reggie (the original author of the ByteFX stuff) became employed by MySql.

B.
 
Thanks:

I am goind to try switching to MySQL Connector.NET 1.0.5. I hope that it is used in basically the same way as the ByteFX connector.
 
WOW!! All I did was remove my reference to ByteFX, add a reference to the MySQL Connector.NET and everything works perfectly! Thanks penfold69!
 
Back
Top