netsky_lt 发表于 2006-4-28 14:50:28

QTP对Oracle数据库连接?

Oracle数据库连接:
dim Setconn
Set conn = CreateObject("ADODB.Connection")
conn.Open "driver={?????};server=192.168.0.2;uid=test;pwd=test;database=DatabaseName"
If conn.State = 0 Then
   Reporter.ReportEvent micFail, "testing", "连接数据库失败"
else
   Reporter.ReportEvent micPass, "testing",   "连接数据库成功"
End If

其中driver={?????};应怎样写?

[ 本帖最后由 netsky_lt 于 2006-4-28 16:26 编辑 ]

netsky_lt 发表于 2006-4-28 15:27:36

本地数据源设置连接成功

driver={oracle in oraHome92}

错误:ORA-12560: TNS: 协议适配器错误

[ 本帖最后由 netsky_lt 于 2006-4-28 16:32 编辑 ]

investmark 发表于 2006-4-28 17:17:02

先进行odbc的设置,然后就可以使用下面的函数
Function OpenConnection (dataSource)
        Set cnn = CreateObject("ADODB.Connection")
        cnn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=true;User ID=taobao;Password=taobao;Data Source=" &dataSource
    cnn.Open
        Set OpenConnection = cnn
End Function

songfun 发表于 2006-4-28 20:12:16

好!

netsky_lt 发表于 2006-4-29 11:30:51

郁闷

我用三楼的脚本,运行时没有执行啊,报告没报错;还要其它设置么?odbc:测试时能连接上(oracle in oraHome92),用PL/SQL Developer能对数库操作.
脚本写错?
Function OpenConnection (dataSource)
      Set cnn = CreateObject("ADODB.Connection")
      cnn.ConnectionString = "Provider=oracle in oraHome92;Persist Security Info=true;User ID=XXX;Password=XXX;Data Source=192.168.0.2" &dataSource
    cnn.Open
      Set OpenConnection = cnn
If cnn.State = 0 Then
   Reporter.ReportEvent micFail, "testing", "连接数据库失败"
else
   Reporter.ReportEvent micPass, "testing",   "连接数据库成功"
End If

End Function

另一种:
Set Conn = CreateObject("ADODB.Connection" )
Conn.open "DRIVER={oracle in oraHome92};SERVER=192.168.0.2;PORT=1521;DATABASE=DBSERVER; USER=ebmsghyy20060329;PASSWORD=ebmsghyy20060329;"
Set Rs = CreateObject ("ADODB.Recordset" )

If conn.State = 0 Then
   Reporter.ReportEvent micFail, "testing", "连接数据库失败"
else
   Reporter.ReportEvent micPass, "testing",   "连接数据库成功"
End If

错误:ORA-12560: TNS: 协议适配器错误

netsky_lt 发表于 2006-4-29 15:29:08

搞掂!

Dim Cnn
Set Cnn = CreateObject("ADODB.Connection")
Cnn.ConnectionString = "Provider=MSDAORA.1;Data Source=DBSERVER;Password=XXX;User ID=XXX;Persist Security Info=True"

Cnn.Open
If Cnn.State = 0 Then
   Reporter.ReportEvent micFail, "testing", "连接数据库失败"
else
   Reporter.ReportEvent micPass, "testing",   "连接数据库成功"
End If


Step Name: testing


Step Passed

ObjectDetailsResultTime
   
testing 连接数据库成功 Passed 2006-4-29 - 15:19:33

FLY000 发表于 2011-5-30 11:41:52

Dim Cnn
Set Cnn = CreateObject("ADODB.Connection")
Cnn.ConnectionString = "rovider=MSDAORA.1;Data ...
netsky_lt 发表于 2006-4-29 15:29 http://bbs.51testing.com/images/common/back.gif


QTP    连接数据库,是不是要先在本地创建ODBC连接设置,再在程序里写连接语句才能使用?

bagwell333 发表于 2011-5-30 13:23:21

http://www.51testing.com/index.php?uid-173503-action-viewspace-itemid-206138

wendy.wang 发表于 2011-6-7 13:32:39

哈哈
页: [1]
查看完整版本: QTP对Oracle数据库连接?