databaseconnection

Connection failure - ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10061)


I am trying to make a connection between Visual Studio 2010 Ultimate and SQL Server. I just made a small program just to see if the connection works.

Every time I'm trying to connect, VS throws an ODBCexception.

"ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10061)"

This is my connectionstring:

DRIVER={MySQL ODBC 3.51 Driver};Data Source=MY-USERNAME\\SQLEXPRESS;Initial Catalog=MY-DATABASE;Integrated Security=True

This connection string was copied from a data connection I've made inside VS.

Do any one have a solution?


Solution

  • Right now, you're mixing the MySQL driver (DRIVER={MySQL ODBC 3.51 Driver}) with a Microsoft SQL Server Express server name (Data Source=MY-USERNAME\\SQLEXPRESS;) - which one do you really want to connect to??

    If you want to connect to SQL Server Express (which comes bundled with Visual Studio), you need to use the native .NET SQL client (and not the ODBC stuff).

    In that case, your connection string would be something like:

    server=YourMachine\\SQLEXPRESS;Database=MYDATABASE;Integrated Security=True
    

    or something similar - see ConnectionStrings.com for tons of samples.

    In this case, you should use classes like SqlConnection, SqlCommand, SqlDataReader from the System.Data.SqlClient namespace in your application.