views:

241

answers:

2

Whenever I try to connect to MySql using vbscript, I'm getting an error:

Script: E:\VBScript\CreateAccount.vbs
Line: 6
Char: 1
Error:[Microsoft][ODBC Driver Manager] Data source name too long
Code: 80000405
Source Microsoft OLEDB Provider for ODBC drivers

Here's the code to open the connection to Mysql:

dim cn, rs

set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
cn.connectionstring = "driver={MySQL ODBC 5.1 Driver}; Data Source=E:\Important\mysql-5.1.39-win32\bin\mysqld;Database=mail; User Id=root; Password = ;"
cn.open

How can I enable vbscript to connect to Mysql?

+2  A: 

The connection string looks odd. Shouldn't it be like this?

Driver={MySQL ODBC 5.1 Driver};
Server=<x.x.x.x>;
Database=<dbname>
Uid=root
Pwd=<pwd>

<x.x.x.x> probably is localhost or 127.0.0.1
<dbname> is the name of the database in that mySQL server instance
<pwd> is blank for your case

Update:

Before attempting to connect via ODBC, you need to install the driver. It can be downloaded from http://dev.mysql.com/downloads/connector/odbc/

You'll then need to configure the ODBC data source, instructions at:
http://dev.mysql.com/doc/refman/5.0/en/connector-odbc-configuration-dsn-windows.html

o.k.w
+1, also take a look here: http://connectionstrings.com/mysql
Rubens Farias
I'm still getting an error: [Microsoft][ODBC driver Manager] Data source name not found and no default driver specifiedThis is show I'm trying to connect:cn.connectionstring = "Driver={MySQL ODBC 5.1 Driver};server=localhost;Database=mail; Uid=root; Pwd= ;"
Dusk
Have you tried connecting to the DB from other apps? E.g. mySQL's GUI Tools?
o.k.w
Take a look at my updated answer, if you might missed out the ODBC configuration.
o.k.w
A: 

A very wild guess, but can you try removing the spaces from in between the arguments? According to this, the same message appears when using commas instead of semicolons to split the values.

Also, you don't happen to have special characters in your root password?

Pekka