Micro Focus QTP (UFT) Forums

Full Version: Data base connection problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am having trouble with oracle database connection, how should I know my connection is success or not. When I run the script it is giving 0 failed result, any sample code is very helpful. Please check the below sample code

Code:
Dim OdbcDSN
Dim connect, sql, resultSet
Dim dbConn
Dim rsGetAccountData
Dim strSQL, strCategory, strCategoryType
Dim a1
On Error Resume Next
Public Sub SetDBConnection
   'Purpose:  Set the database connection
Set dbConn = CreateObject("ADODB.Connection")
dbConn.ConnectionString = "DSN=sys_qtp_ora;Server=test;Uid=username;Pwd=password;"
dbConn.Open
End Sub
Public Sub GetAccountData()
   Set resultSet = CreateObject ("ADODB.RecordSet")
   'Purpose:  Get the account data information from table
    strSQL = "select  first_name,last_name  from   names where rownum <10"
              '  strSQL = "insert into aaa values(1234)"
resultSet = dbConn.Execute(strSQL)
'MsgBox "Hello everyone!"
MsgBox "Not Connected" & resultSet
Do While Not resultSet.eof

If a1  = 10 then
   MsgBox "reddy" & resultSet("first_name")
        end if
resultSet.MoveNext
Loop
resultSet.Close

End Sub

Call SetDatabase()
Call GetAccountData()
Please do not post multiple same questions. I have deleted your second post
Hi,

This is the sample script to connect to the DB(presently i used it for MS Access). It may helpfule to u:

Code:
conStr="DSN=sampleDB"
qryStr="select * from empTable"

Set conObj=CreateObject("ADODB.connection")
Set cmdObj=CreateObject("ADODB.Command")
Set recObj=CreateObject("ADODB.RecordSet")
'Set fieldObj=CreateObject("ADODB.field")
conObj.open conStr

Set cmdObj.activeconnection=conObj
cmdObj.commandtext=qryStr

Set recObj=cmdObj.execute

While Not recObj.EOF
    MsgBox(recObj.fields(1))
    recObj.movenext
Wend
Thanks & Regards,
Uday.
I didnot do it intentionally, it might be a mistake.
Dear Ashley,
Read this about Database Example.

https://www.learnqtp.com/forums/Thread-DatabaseExample