10
votes

I'm trying to connect to a MySQL database using my ASP.NET Web Forms Application. I'm carrying out a test to Bind the data from the MySQL database to a GridView.

Here is my code:

Dim strMySQLConn As String = "DRIVER={MySQL ODBC 5.1 Driver};Database=database_name;Server=ip_address;UID=username;PWD=password;"
    Dim MySQLConn As New OdbcConnection(strMySQLConn)

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            Dim ds As DataSet = New DataSet()
            Dim cmdMySQL As New OdbcDataAdapter("SELECT * FROM categorymaster", MySQLConn)

            MySQLConn.Open()

            cmdMySQL.Fill(ds, "prjs")

            gv.DataSource = ds.Tables("prjs").DefaultView
            gv.DataBind()


            MySQLConn.Close()

        End If
    End Sub

However, when the MySQL database connection is made (MySQLConn.Open()), the following error is returned:

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

Why is this and how can I prevent it from happening?

Also, what are the possible reasons for seeing this error? If login credentials were incorrect, would this error be shown?

5
simillar question check this out it my help you stackoverflow.com/questions/3294024/…Karthik
@karthi - I've changed my conn string to DRIVER={MySQL ODBC 5.1 Driver};, but I'm still getting the same errorCurt
Is the driver installed? ODBC gives this error if it can't load the driver as well.Romain
@Romain "MySQL ODBC 5.1 Driver" is installed, but I'm still getting this errorCurt
@Curt ASP.net has to be able to load it. If your machine is x86_64, you might have installed either the 32- or 64-bits version. You'll need to have installed the one with the same architecture as your ASP server.Romain

5 Answers

11
votes

The issue was caused because I was installing a 64-bit MySQL ODBC 5.1 Driver, because my OS is running 64 bit.

Because I've been trying to solve this for days, as a long shot I deleted the driver, and installed 32-bit MySQL ODBC 5.1 Driver.

This has fixed the error and I'm now making a successful connection.

4
votes

Curt was right. I was having this exact issue. Since I had MySQL Workbench installed on my workstation, I assumed I had the drivers installed; Nope. Installing the driver plus calling it by the correct version, and adding command "Provider=MSDASQL;" to the connection string due to the fact that I'm on a 64-bit system solved the issue for me. If you want to see all the ODBC drivers installed on your Windows system, open the registry editor to:

\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers.

There you will find out if the MySQL driver is installed, and if so, its correct name.

This Link will take you to the MySQL Drivers Download site.

3
votes

You might want to check to see if the driver is installed. Here is a guide to getting the list

Check to see if you have any installed and also make sure your version matches with the one in your connection string.

You should be able to download a driver Here

3
votes

My solution of "Data source name not found" (with 5.2.4 ODBC ansi driver, Win7 64bit):

1) Install 64bit ODBC MySQL driver - it should be visible in ODBC Drivers.

2) Install 32bit ODBC MySQL driver - it is invisible in ODBC drivers, but create a "shadow" installation in Program Files x86.

That's all.

1
votes

My problem was that I had on my code

DRIVER={MySQL ODBC 5.3 Driver}, but when I did look up the ODBC trough the windows searcher engine I found an app called ODBC Data Sources, in that app under the Drivers tab I found the name of the drives was {MySQL ODBC 5.3 ANSI Driver}. That fixed the problem.