Search code examples
asp.netmysql

Connecting to MySQL causes error "Data source name not found and no default driver specified"


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?


Solution

  • 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.