一步步教你:QTP连接oracle数据库
上一篇 /
下一篇 2009-12-30 16:47:30
/ 个人分类:02 测试随笔
1. 安装oracle
2. 创建odbc数据源。细节参考其他的总结文章
3. 以文本编辑器打开.udl文件,里面有一串连接数据库的字符串,拿这个字符串,并且在这个字符串里增加Password以分号隔开。比如:udl文件里的字符串为:
Provider=MSDASQL.1;Persist Security Info=False;User ID=emall;Data Source=sfodbc
此时增加密码后为:
Provider=MSDASQL.1;Persist Security Info=False;User ID=emall;Password=emall;Data Source=sfodbc
4. 此时打开qtp,直接复制以下代码运行:
-----------------------------------
Dim StrCon
Dim Res,Cmd
Set Res = CreateObject("ADODB.Recordset")
Set Cmd = CreateObject("ADODB.Command")
'以下为建立连接
StrCon ="Provider=MSDASQL.1;Persist Security Info=False;User ID=emall;Password=emall;Data Source=sfodbc;"
Cmd.activeconnection=StrCon
Cmd.CommandType =1
'以下为执行sql
Cmd.CommandText="select count(*) from ep_account "
Set Res = Cmd.Execute()
Do while not Res.eof
Msgbox(Res(0))
Res.MoveNext
Loop
'以下为关闭数据库连接
Set Res=nothing
Set Cmd.activeconnection=nothing
Set Cmd=nothing
--------------------------------------------
收藏
举报
TAG: