I am trying connect to MySQL database from ASP.net code. some my connection is not working.
for the below code I am getting invalied argument DRIVER. Can you help me to correct this.
Or show me some sample code.
Label1.Text = ""
Label2.Text = ""
Try
Dim conStr As New SqlClient.SqlConnection
conStr.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" +
"SERVER=localhost;" +
"DATABASE=aa;" +
"UID=aa;" +
"PASSWORD=aa;" +
"OPTION=3"
Response.Write("Connection string: " & conStr.ConnectionString)
conStr.Open()
If conStr.State = ConnectionState.Open Then
Label1.Text = "SQLConnection conStr is Open"
conStr.Close()
ElseIf conStr.State = ConnectionState.Closed Then
Label1.Text = "SQLConnection conStr is closed"
End If
Catch sqlxcp As SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Finally
End Try
Thanks
SqlClientis for SQL Server. With the connection string above you need to use the OBBC provider classes (from here):Using the
MySql.Data.MySqlClient.MySqlConnectionclass, MySQL connection should be of this form:(Default port is 3306)
If you are using the MySQL Connector/ODBC 3.51 (which your code suggests):
The ConnectionStrings site is a great resource.