ADODB MySQL and VB6 (1 Viewer)

resp

New member
Local time
Today, 08:11
Joined
Sep 19, 2007
Messages
3
im using:
Function CnnString() As String
Dim strServerName As String
Dim strDatabaseName As String
Dim strUserName As String
Dim strPassword As String

'Change to IP Address if not on local machine
'Make sure that you give permission to log into the
'server from this address
'See Adding New User Accounts to MySQL
'Make sure that you d/l and install the MySQL Connector/ODBC 3.51 Driver

strServerName = "localhost"
strDatabaseName = "DBname"
strUserName = "user"

CnnString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & strServerName & _
";DATABASE=" & strDatabaseName & ";" & _
"USER=" & strUserName & _
";PASSWORD=" & strPassword & _
";OPTION=3;"
End Function

as string and:
Dim strSql As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open CnnString()
strSql = "<my data source name>"
On Error GoTo Command1_Click_Error
rs.Open strSql, cn
Command1_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
Exit Sub

to connect.
yea, its SJ's code...
well, the error i get is
"You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'my data source name'".
i have xampp for mysql and ye, i installed the 3.51 odbc driver
any ideas? :S
thanx in advance
 

Salient

Registered User.
Local time
Tomorrow, 01:11
Joined
Aug 14, 2007
Messages
63
im using:
Function CnnString() As String
Dim strServerName As String
Dim strDatabaseName As String
Dim strUserName As String
Dim strPassword As String

'Change to IP Address if not on local machine
'Make sure that you give permission to log into the
'server from this address
'See Adding New User Accounts to MySQL
'Make sure that you d/l and install the MySQL Connector/ODBC 3.51 Driver

strServerName = "localhost"
strDatabaseName = "DBname"
strUserName = "user"

CnnString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & strServerName & _
";DATABASE=" & strDatabaseName & ";" & _
"USER=" & strUserName & _
";PASSWORD=" & strPassword & _
";OPTION=3;"
End Function

as string and:
Dim strSql As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open CnnString()
strSql = "<my data source name>"
On Error GoTo Command1_Click_Error
rs.Open strSql, cn
Command1_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
Exit Sub

to connect.
yea, its SJ's code...
well, the error i get is
"You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'my data source name'".
i have xampp for mysql and ye, i installed the 3.51 odbc driver
any ideas? :S
thanx in advance

The error you are getting sounds like MySQL is objecting if that's any helpes. Sorry use MySQL with PHP but haven't tried with vb6.

Should strPassword have a value?
 

resp

New member
Local time
Today, 08:11
Joined
Sep 19, 2007
Messages
3
actually i didnt saw that i miss the password, but having no pwd in sql it wouldn't matter anyway, i just tried adding that one too.
the error says the syntax problem is near my strSql ("<my data source name>")

maybe strSQL shouldnt be given 'my data source name' value? :confused:
 

Salient

Registered User.
Local time
Tomorrow, 01:11
Joined
Aug 14, 2007
Messages
63
Just on the off chance, can you access the database via the MySQL control panel?
 

Users who are viewing this thread

Top Bottom