Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connect to MySql DB using ADO in VB with MyODBC 3.51

Status
Not open for further replies.

lleemon

Programmer
Mar 26, 2002
21
GB
I am trying to connect to a MySql db that isn't local. I have the following code that looks right but gives me the following error:

Run-time error '-2147467259 (8004005)':
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

Here is my code that I have in a command click:
Dim adoCon As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim strCon As String
Dim strSQL As String

strCon = "Driver={mySQL};" & _
"Server=something.com;" & _
"Port=3306;" & _
"Option=131072;" & _
"Stmt=;" & _
"Database=db_name;" & _
"Uid=name;" & _
"Pwd=pwd;"

Set adoCon = New ADODB.Connection
With adoCon
.ConnectionString = strCon
.Open
End With

Set adoRs = New ADODB.Recordset
strSQL = "SELECT * " _
& " FROM table;"

With adoRs
.CursorLocation = adUseClient
.ActiveConnection = adoCon
.Open strSQL
End With

Do While adoRs.EOF = False
MsgBox adoRs.Fields("Model") & " " & adoRs.Fields("Brand")
adoRs.MoveNext
Loop

adoRs.Close
Set adoRs = Nothing
adoCon.Close
Set adoCon = Nothing

..............

I also do have a reference to Microsoft ActiveX Data Object 2.5 Library.

I was able to create a DSN on my machine which does allow it to work but I want to be able to distribute this to a few other people. So DSN-less would be much better.

If anyone can give me some advice that would be great.

Thanks.
 
Here's what helps me.
1. Build a connection using a data control object. Test it.
2. Cut and paste that connection string and attached it to a variable (properties window).
2.5 Throw the data control away.
3. Make your connection using the string.
4. Create your SQL statement and open the recordset.

Any questions .. .. vb_doc@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top