Not able to connect to Mysql using vbscript
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 OL开发者_StackOverflow中文版EDB 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?
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
I had the same issue, here is what I did to resolve.
Verify ODBC MySQL Driver version by going to start0->control panel->administrative tools->Data Sources(ODBC)->Click on Driver Tab.
I have MySQL ODBC 5.3 UNICODE Driver, so for my connection string I put "Driver={MySQL ODBC 5.3 UNICODE Driver};Server=localhost;Database=databasename;User=username;Password=password;Option=3;"
NOTE: if you do not see a MySQL driver listed in Data Sources and you know you have installed the MySQL connector, then figure out which bit version (32 or 64) you installed previously and install the other.
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?
精彩评论