QTP连接MySQL

C:\Windows\SysWOW64\odbcad32.exe里面对应的是32位的驱动程序
C:\Windows\System32\odbcad32.exe里面对应的是64位的驱动程序
QTP认得是32位的
Dim Conn
'建立数据库连接对象
Set Conn=CreateObject("ADODB.Connection")
Const ConnectionString="DSN=MySQL1;DATABASE=mysql;PWD=root;PORT=3306;SERVER=localhost;UID=root"
'Const ConnectionString="Driver={MySQL ODBC 5.1 Driver};DATABASE=mysql;PWD=root;PORT=3306;SERVER=127.0.0.1;UID=root"
Conn.Open ConnectionString
If Conn.State<>0 Then
    Reporter.ReportEvent micPass,"testing","连接数据库成功"
    '建立记录集对象
    Set res = CreateObject("adodb.recordset")
    sql = "select * from mysql.user"
    res.Open sql, Conn
    Dim i 
    i = 1
    Do While Not res.EOF
        host = res.Fields("Host")
        res.MoveNext
        DataTable.Value("Host","user") = host
        i = i + 1
        DataTable.SetCurrentRow(i)
    loop
    
else
    Reporter.ReportEvent micFail,"testing","连接数据库失败"
End If

你可能感兴趣的:(QTP连接MySQL)