MySQL query error (ODBC 3.51)
I am trying to execute a request in an application VB6
.
Here is my code:
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver}; Server=***; Database=***; Username=***; Password=***; Option=3"
con.Open
Dim cmd As New ADODB.Command
With cmd
.ActiveConnection = con
.CommandText = "SELECT COD_CONFIG FROM FDT_CONFIG"
.CommandType = adCmdText
End With
Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockOptimistic
I have hidden some information in the connection string, but in my application I am using the correct values.
I can successfully open the connection, but when I try to execute the request, I get:
Runtime Error 2147467259 (800004005) ': Unspecified error'
Can someone tell me where I am going wrong?
source to share
If you want to assign an object to an Command
ActiveConnection
existing object Connection
, you must use Set
:
With cmd
Set .ActiveConnection = con
....
End With
This is a little confusing because you can also assign a string to a property ActiveConnection
and ADO will create a custom relationship for you. In this case, you will not use Set
, because you are simply assigning a value to the built-in type (string):
With cmd
.ActiveConnection = "Driver={MySQL ODBC 3.51 Driver}; Server=***; Database=***; Username=***; Password=***; Option=3"
...
End With
Thus, the property can be used in several ways. However, in your scenario, since you are assigning an object reference, you need to use a keyword Set
.
source to share