Question

It has been a long time since using VB6 and I didn't use MySql or DSN connections then, but I'm working on a legacy application that uses these. When I try to open the connect I am getting a Data source not found and no default driver specified with this code

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim sql As String

Set rs = New ADODB.Recordset
Set cmd = New ADODB.Command
Set conn = New ADODB.Connection

conn.Open "DSN=AddressHealthcheck" '<- Fails on this statement

I have also tried specifying the DSN in the conn.ConnectionString but get the same error.

The AddressHealthcheck exists in the local System DSN, uses the MySql ODBC 5.1 Driver and connects successfully when tested.

I'm sure (and hope) I missing something obvious. Any suggestions?

Thanks, Kevin

Was it helpful?

Solution

I use a DSN-less ODBC stored in a UDL. It's basically a file with a connection string in it. Maybe the connection string will be of use. Here's an example:

[oledb]
; Everything after this line is an OLE DB initstring
Provider=MSDASQL.1;Persist Security Info=True;Extended Properties="Driver=MySQL ODBC 5.1 Driver;SERVER=mysqlsvr;UID=userid;PWD=password;DATABASE=mydatabase;PORT=3306;OPTION=18475";Initial Catalog=mydatabase

OTHER TIPS

rags comment (above) wasn't the solution, but it definitely helped track it down.

When using a full connection string the error message was different and much more useful, the driver failed to load.

The issue seems to be that since I'm on a 64 bit machine it was the 64 bit driver. VB6 can't use the 64 bit driver and the 32 bit driver doesn't show up in the ODBC Connection Administrator on a 64 bit machine.

DSN is not an option in my machine.

There are two ODBC Admin tools in a 64-bit system. Run the 32-bit version. Or better yet drop ODBC and get an OLEDB Provider for MySQL.

I was researching this by 1 labour day (yesterday). Today I've realized some errors I had yesterday in order to have this working.

Dim conexion As New ADODB.Connection

conexion.ConnectionString = "DSN = yourDsnName" conexion.open

Don't forget to...

  1. Create a user in your mysql server that has all the priviledges you need.
  2. Assign the server's name or ip from where it is going to connect to mysql
  3. Create your dsn on the client machine with the correct options en test it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top