I have a Visual Studio 2008 C# .NET 3.5 application where I am trying to connect to a locally hosted MySQL 5.1.53 database using System.Data.Odbc.
using (System.Data.Odbc.OdbcConnection c = new System.Data.Odbc.OdbcConnection("Driver ={MySQL ODBC 5.1 Driver}; Server =localhost; Database =mydatabase; User =root; Option =3; "))
{
c.Open();
}
Unfortunately, I get the exception: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I can successfully connect to this database using the VS2008 Server Explorer using the settings:
Data source: .NET Framework Data Provider for ODBC
Use user or system data source name: mydatabase
User name: root
This produces the connection string: Dsn=mydatabase;uid=root Using this connection string in my c# code also yields the same exception.
What do I need to do to connect to this data source successfully in c#?
MySqlConnection.