Connecting to MySQL from VB

Here’s a snippet for connecting to MySQL db server from Visual basic. I’ve found it while trying to clean up an old hard drive. It’s quite primitive but I believe still of use for someone.
Option Explicit
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
Public Function myConnect(dbHost As String, dbUser As String, dbPass As String, dbName As String, dbPort As Integer) 'Connect to MySQL server
Dim constr As String
constr = "Provider=MSDASQL.1;Password=;Persist Security Info=True;User ID=;Extended Properties=" & Chr$(34) & "DRIVER={MySQL ODBC 5.1 Driver};DESC=;DATABASE=" & dbName & ";SERVER=" & dbHost & ";UID=" & dbUser & ";PASSWORD=" & dbPass & ";PORT=" & dbPort & ";OPTION=16387;Max Pool Size=10000;STMT=;" & Chr$(34)
Set conn = New ADODB.Connection
conn.Open constr
End Function
Public Function dbQuery(QueryString As String)
Set rs = New ADODB.Recordset
rs.Open QueryString, conn, adOpenUnspecified, adLockUnspecified
End Function
Public Function dbClose()
If rs.State = 1 Then
rs.Close
End If
End Function
I will surely post more here later as I might find more goodies on this cranky drive.
Spread the word
del.icio.us Digg Furl Google StumbleUpon Technorati Windows Live Yahoo! Help












1 Comment on Connecting to MySQL from VB »
Addy @ 3:05 am:
Pefecrt answer! That really gets to the heart of it!