2009-09-02 29 views
5

我試過下面的腳本,但我得到了一個錯誤:使用純vbscript連接到mysql 5.0數據庫?

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" 

它給了以下錯誤:

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

當我用Google搜索一個ODBC連接我走到this頁面,我可以下載odbc 5.1連接器。想知道這是否足以連接到MySQL服務器5.0數據庫...?

回答

6

安裝MySQL Connector/ODBC和使用connection string像下面

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

沒有這個不行...我已經安裝了5.1連接器正確。 – deostroll 2009-09-02 09:51:03

+0

什麼是錯誤信息? – 2009-09-02 09:54:35

+0

同樣的事情... – deostroll 2009-09-02 09:58:11

1

我做了小的修改上面的腳本和工作正常:

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" 
+0

變量我和變量connectionString沒有定義 – Tanzeel 2017-07-12 23:15:17