Click to See Complete Forum and Search --> : C# vs mySQL


HSN
December 31st, 2005, 03:50 PM
Hi,
I'm trying to use mySQL along with C#.

Here is my procedure for connecting to mysql:



internal void mySQL()
{
string mySQLString = "DRIVER={MySQL};DATABASE=system;";
mySQLString += "SERVER=localhost;";
mySQLString += "UID=root;PWD=1234;";
System.Data.Odbc.OdbcConnection myDb = new OdbcConnection(mySQLString);
try
{
myDb.Open();
}
catch (System.Exception E)
{
MessageBox.Show(E.ToString());
}

}


and I get the following exception:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified


please help me with that.

exterminator
January 2nd, 2006, 05:42 AM
Seems like you connection string is out of the way. Find the suitable one from here - www.connectionstrings.com under MySQL(OleDb) or here it is:

"Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"Hope this helps. Regards.

hspc
January 9th, 2006, 06:55 AM
Did you instal the MySQL ODBC driver? you can find it here (http://dev.mysql.com/downloads/connector/odbc/3.51.html)
Check the connection string.. should be like : DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;
MySQL now has the .NET driver (http://dev.mysql.com/downloads/connector/net/1.0.html). you can use it as an alternative.
It's not recommended to use the MyOLEDB driver.