gold_85 的 QTP手動連接SQL Server/DB2/Oracle數(shù)據(jù)庫的方法 Quicktest professional 各種庫據(jù)庫的聯(lián)接方法,,手動指定SQL語句的寫法,。 一,、SQL Server格式(本地?zé)o需安裝SQL Server) connectionstring(連接字符串): 1.本地沒有創(chuàng)建數(shù)據(jù)源的方式 DRIVER=SQL Server;SERVER=數(shù)據(jù)庫IP地址;UID=用戶名;PWD=密碼;APP=Microsoft Office 2003;WSID=本地主機名;DATABASE=數(shù)據(jù)庫名 實例: DRIVER=SQL Server;SERVER=10.160.11.10;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJHLJUN;DATABASE=dcwork 2.本地已創(chuàng)建數(shù)據(jù)源的方式 DSN=數(shù)據(jù)源名稱;UID=用戶名;PWD=密碼;APP=Microsoft Office 2003;WSID=數(shù)據(jù)庫的主機名;DATABASE=數(shù)據(jù)庫名 實例: DSN=LocalServer;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJDCWORKTEST;DATABASE=dcwork 3.SQL語句實例(從數(shù)據(jù)庫表HR_LANGUAGE_TYPE中,,查詢字段語言名稱LANGUAGE_NAME,,條件語言名稱=中文,,按語言名稱升序排序結(jié)果) source(SQL語句): SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM dcwork.dbo.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME 二,、DB2格式:(本地至少安裝DB2 Run-Time Client Lite) connectionstring(連接字符串): 1.本地沒有創(chuàng)建數(shù)據(jù)源的方式 DRIVER={IBM DB2 ODBC DRIVER};UID=用戶名;PWD=密碼;MODE=SHARE;DBALIAS=數(shù)據(jù)庫名; 實例: DRIVER={IBM DB2 ODBC DRIVER};UID=db2admin;PWD=db2admin;MODE=SHARE;DBALIAS=DCWORK; 2.本地已創(chuàng)建數(shù)據(jù)源的方式 DSN=數(shù)據(jù)源名稱;UID=用戶名;PWD=密碼;MODE=SHARE;DBALIAS=DCWORK; 實例: DSN=DWCORKDB2;UID=db2admin;PWD=db2admin;MODE=SHARE;DBALIAS=DCWORK; 3.SQL語句實例 source:SQL語句 SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DB2ADMIN.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME 三,、Oracle格式:(本地需要安裝Oracle ODBC DRIVER) connectionstring(連接字符串): 1.本地沒有創(chuàng)建數(shù)據(jù)源的方式 DRIVER={Oracle in OraHome92};SERVER=數(shù)據(jù)庫服務(wù)名;UID=用戶名;PWD=密碼;DBQ=數(shù)據(jù)庫名;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=10;TLO=O; 打開QTP 1.insert--checkpoint--database checkpoint 2.在彈出來的窗口選擇第二項 specify SQL ....,然后點下一步,再點create 自己創(chuàng)建一下ODBC,如果能鏈通ORACLE,那在QTP回放應(yīng)該沒有問題 我的是LINUX AS4+ORACLE 10G 在QTP中的腳本是 Dim Cnn Set Cnn = CreateObject("ADODB.Connection") Cnn.ConnectionString ="DRIVER={Oracle in OraClient10g_home1};SERVER=TEST;UID=system;PWD=test;DBQ=TEST;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=Me;CSR=F;FWC=F;FBS=60000;TLO=O;" Cnn.Open If Cnn.State = 0 Then Reporter.ReportEvent micFail, "testing", "連接數(shù)據(jù)庫失敗" else Reporter.ReportEvent micPass, "testing", "連接數(shù)據(jù)庫成功" end if 回放是通過的! 先確定你的ODBC能否正確連通先! 四 MYSQL格式:(本地需要安裝MYSQL ODBC DRIVER) Dim Cnn Set Cnn = CreateObject("ADODB.Connection") Cnn.ConnectionString ="DATABASE=testmysql;DSN=192.168.1.63;OPTION=0;PWD=123456;PORT=0;SERVER=192.168.1.63;UID=root" Cnn.Open If Cnn.State = 0 Then Reporter.ReportEvent micFail, "testing", "連接數(shù)據(jù)庫失敗" else Reporter.ReportEvent micPass, "testing", "連接數(shù)據(jù)庫成功" end if 2.本地已創(chuàng)建數(shù)據(jù)源的方式 DSN=數(shù)據(jù)源名稱;UID=用戶名;PWD=密碼;DBQ=數(shù)據(jù)庫名;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0; 實例: DSN=dcworkoracle;UID=DCWORK;DBQ=DCWORK;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0; 3.SQL語句實例 source:SQL語句 SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DCWORK.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME 五 access Set Conn = CreateObject("ADODB.Connection" ) str="Provider=Microsoft.Jet.OLEDB.4.0;Da ta Source=c:/db1.mdb" Conn.open str Set Rs = CreateObject ("ADODB.Recordset" ) |
|