none
Having a problem with OdbcConnection() RRS feed

  • Question

  • I attempt to make a database connection (with the right details, I have checked) and I receive this error:

    ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. I'm assuming there is an issue with "Driver={MySQL ODBC 5.1 Driver};" but I am not sure.

    Here is my code:

            public static bool openConnection(string dbHost, int dbPort, string dbName, string dbUsername, string dbPassword)
            {
                try
                {
                    Out.WriteLine("Connecting to " + dbName + " at " + dbHost + ":" + dbPort + " for user '" + dbUsername + "'");
                    dbConnection = new OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=" + dbHost + ";Port=" + dbPort + ";Database=" + dbName + ";User=" + dbUsername + ";Password=" + dbPassword + ";Option=3;");
                    dbConnection.Open();
                    Out.WriteLine("Connection to database successfull.");
                    return true;
                }
    
                catch (Exception ex)
                {
                    Out.WriteError("Failed to connect! Error thrown was: " + ex.Message);
                    return false;
                }
            }

    Anyone know the problem?

    • Moved by Blair Allen Stark Sunday, September 16, 2012 10:39 PM proper forum (From:Visual C# General)
    Sunday, September 16, 2012 7:29 PM

Answers

  • Not sure.... but why are you not using the ADO.Net provider for mysql?

    Also, for debugging connection strings, create a file on your desktop "test.udl"

    double click it and use the DataLinks interface to configure a connection string to the data source you desire.

    Once the connection tests successfully, open the udl file in notepad, and confirm you are building the connection string in your application using the same format as the connectin string in the udl.

    you can also a properly formatted connection string in a resource, and use it to initialize a connection string builder. And then use the connection string builder API to generate you connecitn string.

    see:

    http://msdn.microsoft.com/en-us/library/ms254947.aspx


    gimme some slamming techno!!!!

    Sunday, September 16, 2012 7:45 PM
  • Hi GConscience,

    Have you install MySQL ODBC Driver on the machine? Is the target platform is correct?

    Check if the following link helps.

    http://stackoverflow.com/questions/6492868/data-source-name-not-found-and-no-default-driver-specified-error

    Besides, since you are using MySQL ODBC Driver, I suggest you to create a new thread in MySQL forum.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, September 18, 2012 6:19 AM
    Moderator

All replies

  • Not sure.... but why are you not using the ADO.Net provider for mysql?

    Also, for debugging connection strings, create a file on your desktop "test.udl"

    double click it and use the DataLinks interface to configure a connection string to the data source you desire.

    Once the connection tests successfully, open the udl file in notepad, and confirm you are building the connection string in your application using the same format as the connectin string in the udl.

    you can also a properly formatted connection string in a resource, and use it to initialize a connection string builder. And then use the connection string builder API to generate you connecitn string.

    see:

    http://msdn.microsoft.com/en-us/library/ms254947.aspx


    gimme some slamming techno!!!!

    Sunday, September 16, 2012 7:45 PM
  • Hi GConscience,

    Have you install MySQL ODBC Driver on the machine? Is the target platform is correct?

    Check if the following link helps.

    http://stackoverflow.com/questions/6492868/data-source-name-not-found-and-no-default-driver-specified-error

    Besides, since you are using MySQL ODBC Driver, I suggest you to create a new thread in MySQL forum.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, September 18, 2012 6:19 AM
    Moderator