Brinkster Knowledge Base
How do I connect to a MySQL database with ASP.NET 2.0
IMPORTANT: Be sure to make note of the following when using these coding examples:
1. Replace username with your Brinkster hosting account username.
2. Replace password with the password for the email account used above.
3. Please log into your account, select the web site settings, and use the correct server hostname.
MySQL Database
*If you are currently using the ByteFX MySQL data provider, the previous code sample in this article will continue to work.
*In order for this example to work on your local machine, you need to download the latest MySQL Connector from http://dev.mysql.com and install it on your machine. This will generate a dll called MySql.Data.dll that also must be uploaded to your bin folder. You must have the MySql.Data.dll in your bin folder for this example to work.
*Your specific mySQL server is listed in Website Settings of the account control panel (it is not mySQL??).
<%@ Import Namespace="mysql.data.SqlClient" %> <%@ Import Namespace="System.Data.Odbc" %> <%@ Page language="VB" %> <% Dim connString As String = "Driver={MySQL ODBC 3.51 Driver};" & _ "Server=host.domain.com;" & _ "Database=username;" & _ "user id=username;" & _ "password=password;" & _ "pooling=false"
Dim con As OdbcConnection = New OdbcConnection(connString) Dim cmd As OdbcCommand = Nothing Dim oDR As OdbcDataReader = Nothing Dim sSQL As String = "select * from tablename" cmd = New OdbcCommand(sSQL, con) con.Open() Try oDR = cmd.ExecuteReader If oDR.HasRows Then While oDR.Read 'Hanlde Data End While End If Catch ex As Exception Finally CType(cmd, IDisposable).Dispose() If Not oDR Is Nothing Then oDR.Close() con.Close() End Try %> |