Connect to mysql 5.0 database using pure vbscript?

I tried the below script, but I get an error:

dim cn, rs

set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
cn.connectionstring = "Provider=MysqlProv; Data Source=Adonis; User Id=mysqluser; Password = mysqlpass;"
cn.open
rs.open "select * from Countries", cn, 3
rs.MoveFirst
while not rs.eof
    wscript.echo rs(0)
    rs.next
wend
cn.close
wscript.echo "End of program"

It gives the following error:

C:\mysql.vbs(6, 1) ADODB.Connection: Provider cannot be found. It may not be pro
perly installed.

When I googled for the odbc connector, I went to this page where I could download the odbc 5.1 connector. I wonder if this is enough to connect to the mysql server 5.0 database ...?

+5
source share
2 answers

Install MySQL Connector / ODBC and use the connection string as shown below

connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=yourServerAddress;" & _
                   "Database=yourDataBase;User=yourUsername;" & _
                   "Password=yourPassword;"
+6
source

I made small changes to the above script and it works fine:

dim cn, rs

i = 0

set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")

connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;" & _
                   "Data Source=dsn_hb; Database=TP; User=root; Password=***;"

cn.Open connectionString
rs.open "select * from test.Login", cn, 3
rs.MoveFirst

'msgbox rs(0)'

while not rs.eof
    msgbox rs.Fields(0)
    rs.MoveNext
wend

cn.close

MsgBox "End of program"
+1

All Articles