1

I'm trying to connect to a MySQL database from within a VBS script, but I can't get passes a specific error -

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I'm running 64-bit Windows 7 (from where the script is running), and the MySQL DB is running on 32-bit Linux. I've tried both the 32- and 64-bit drivers on Windows 7, downloaded from the Download Connector/ODBC page on the MySQL website, but the error persists.

I have found a couple of pages about this issue (including this one), but I've been unable to resolve my issue. How can I make the DB connection I require?

Dim Connection : Set Connection = CreateObject("ADODB.Connection")
Dim RS : Set RS = CreateObject("ADODB.Recordset")

Dim dbConStr : dbConStr = "Driver={MySQL ODBC 5.3.6 Driver};Server=https://mysqlserver.mydomain.com;Data Source=dsn_hb; Database=MyDatabase; User=MyUser; Password=MyPassword;"

Connection.Open dbConStr
RS.open "SELECT * FROM apklibrary.djg_local_archive_scans", Connection, 3
RS.MoveFirst

While Not RS.EOF
    Call MsgBox (RS.Fields(0), vbOkOnly, "POW!")
    RS.MoveNext
Wend

Connection.close

Set Connection = Nothing
Set RS = Nothing

Call MsgBox ("No more records to show you.", vbOkOnly, "Job done")
Community
  • 1
  • 1
David Gard
  • 11,225
  • 36
  • 115
  • 227
  • Shouldn't it look like `Server=https://mysqlserver.mydomain.com; Data Source=dsn_hbSource` (the semicolon ; is what I mean) in your dbConStr? Simple typo? – tobi6 May 31 '16 at 15:10
  • Well spotted, I've corrected that in the example, sadly it wasn't the issue in real life though. – David Gard May 31 '16 at 15:16

1 Answers1

3

The specified driver name is invalid. Valid MyODBC 5.3 driver names:

{MySQL ODBC 5.3 ANSI Driver}
{MySQL ODBC 5.3 Unicode Driver}

Another problem is Server. You should specify the server's address without https://.

Also, since you have user name and password Data Source=dsn_hb; looks redundant, remove it. If not please give us more detail.

So, give a try this:

dbConStr = "DRIVER={MySQL ODBC 5.3 Unicode Driver};Server=mysqlserver.mydomain.com;Database=MyDatabase;User=MyUser;Password=MyPassword;"
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64
  • Thank you for the feedback, that has cleared the issue as described in my question. Unfortunately I am still encountering a problem though, with the message `[MySQL][ODCBC(w) Driver]Unknown MySQL server host (2)` displayed. The server address is 100% correct, and is accessible from my current location. – David Gard Jun 01 '16 at 07:23
  • Never mind, I figured out that I was using the incorrect server address for this type of connection. All sorted, thanks for you help. – David Gard Jun 01 '16 at 07:46