QTP链接oracle数据库方法
上一篇 /
下一篇 2011-08-02 16:39:38
1.设置oracle 的数据源
方法:运行-->control-->管理工具-->数据源-->在“用户DSN”菜单栏下添加
一个oracle的驱动程序
2.在桌面生成一个udl文件,获取链接字符串
方法:桌面新建一个txt文件,将后缀名改为.udl ,在“提供程序”菜单栏下选择provider for oracle 并且点击“下一步” 输入服务器名称 、用户名以及密码点击“测试链接”链接成功,用txt或写字板 打开获得链接字符串
3.在qtp中写上连接的代码,如
Option explicit
Dim conn ,rs,strsql,arry
Set conn = createobject("ADODB.Connection")
conn.ConnectionString = "Provider=MSDAORA.1;Password=lcmis2;User ID=lcmis2; Data Source=LCMIS43;Persist Security Info=True"
conn.Open
If conn.State = 0 Then
reporter.ReportEvent micFail ,"testing" ,"数据库链接失败"
else
reporter.ReportEvent micPass ,"testing","数据库链接成功"
End If
If conn.State <> 0 Then
Set rs = createobject("ADODB.recordset")
strsql = "select * from rec_user "
rs.Open strsql,conn
End If
arry = rs.GetRows
If not rs.EOF Then
For i = 0 to ubound(arry,2)
For j = 0 to ubound(arry,1)
msgbox arry(i,j)
Next
Next
End If
msgbox ubound(arry,2)+1 获取链接表里面的总数行
msgbox ubound(arry,1)+1 获取链接表里面的总数列
收藏
举报
TAG: