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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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_MACHINESOFTWAREODBCODBCINST.INIODBC 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.
Method 3
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
Method 4
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.
Method 5
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0