Knowledgebase: ASP .NET / ASP
How do I connect to the MySQL server using Classic ASP?
Posted by Arvand Sabetian (Import) on 28 May 2009 04:37 AM
Please use the following connection string on our Windows 2008 servers to connect to the local MySQL service:



DBNAME and USERNAME and PASSWORD are what you've already specified in the control panel under MySQL databases.

(125 vote(s))
Not helpful

Comments (12)
David Tillery
05 October 2009 08:54 PM
Of course, there is a whole lot more than just the connection string.
You can find this elsewhere on the web, but I thought it might help if you could just cut and paste right from here and get going, immediately!
1) You will have to create a database with a table with at least one record.
2) My database is called contactmanagerdb.
3) I am using a table called contacts.
4) The way this is coded, it doesn't matter what columns you use, but do put a record in so you can see results.
5) Create a user for the database (my user id is magict) and give the user a password.
6) Cut and paste the following code into ado.aspx and ftp it up to your wwwroot folder, then change the db, table, user and password values in the code.
7) Execute the ado.aspx from your browser.

<%@ Import Namespace="System.Data.ODBC" %>
<%@ Import Namespace="System.Data" %>
<title>Get Data from a Database</title>
<script runat="server" language="VB">
Sub Page_Load()

Dim sConString as String = "DRIVER={MySQL ODBC 5.1 Driver};uid=magict;password=*******;Server=;Option=3;Database=contactmanagerdb;"
Dim objConn as ODBCConnection = new ODBCConnection(sConString)
Dim sSQL as string = "Select * FROM contacts"
Dim objDataAdapter as ODBCDataAdapter = New ODBCDataAdapter(sSQL, objConn)
Dim objDataSet as DataSet = new DataSet()
objDataGrid.Datasource = objDataSet

End Sub

<br /><br /><br />
<table width = 68% cellpadding=2 cellspacing=2 align=center border=1>
<td Font="Arial">
<form runat="server">
<asp:DataGrid id="objDataGrid" runat="server" />
<td font=Arial>
<a href="dotnetmain.aspx">Return to <b>Main Page</b></a>


19 March 2011 04:58 AM
Even then it shows an same error, i don't think the server contains MySQL ODBC Driver-MyODBC has installed?
Arvand Sabetian
20 March 2011 01:09 PM
Some customers have reported that they need to use a port number with the ODBC. So instead of, you would use,1433 or localhost,1433
Lalchandra Rampersaud
05 June 2013 08:42 PM
I have created the ado.aspx file and uploaded it to the server, but it is giving an error. The database and credentials are correct.
Michael Carr
07 June 2013 08:21 AM
I would suggest creating a support ticket and we will be glad to take a look for you.
William Donizete
29 June 2014 05:56 AM
Help-me, in my ASP Classic the following error occurs:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Michael Carr
08 July 2014 12:54 PM
Please create a support ticket. This could be coding or application pool related.
Riyas Mohamed
17 February 2015 07:21 PM
Try the following
Driver={MySQL ODBC 5.2 UNICODE Driver};Server=localhost;Database=myDataBase;


Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;Database=myDataBase;
Ryan C
26 February 2015 02:46 PM
We appreciate this feedback, and hope it will be helpful to other users.
Keyur Mistry
15 May 2015 01:23 AM
I think this answer is not useful for me. I have tried following connection string but it gives me error of "Keyword not supported.
Parameter name: driver"

<add name="MVCCMSContext" providerName="MySql.Data.MySqlClient" connectionString="Driver={MySQL ODBC 5.2 UNICODE Driver};SERVER=;DATABASE=MYDATABSE;UID=MYUSER;PWD=MYPASSWORD;OPTION=3;" />

and if I tried tro remove "Driver" & "option" from the connection string, my connection string is as follows and it gives me an error of "An established connection was aborted by the software in your host machine"

<add name="MVCCMSContext" providerName="MySql.Data.MySqlClient" connectionString="SERVER=;DATABASE=MYDATABSE;UID=MYUSER;PWD=MYPASSWORD;" />
Ajit Mane
17 May 2015 11:44 PM
Open IIS , In Application Pools select DefaultAppPool which you are using to run your application, go to advanced settings and make Enable 32 bit application to True
Ryan C
28 May 2015 02:28 PM
Thank you for the feedback!
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).