Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data base connection problem
#1
Solved: 10 Years, 9 Months, 1 Week ago
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()
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
Please do not post multiple same questions. I have deleted your second post
Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
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.
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
I didnot do it intentionally, it might be a mistake.
Reply
#5
Solved: 10 Years, 9 Months, 1 Week ago
Dear Ashley,
Read this about Database Example.

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  [UFT] Connection String for Oracle robertosalemi 6 11,713 01-15-2016, 04:51 PM
Last Post: robertosalemi
  DB2 Connect connection with IE 11 SRP 1 2,409 12-18-2015, 12:41 PM
Last Post: vinod123
  IBM DB2 connection with VB script bmurali 2 10,435 12-18-2015, 12:38 PM
Last Post: vinod123
  Connection with HP ALM hachem 0 2,405 02-26-2015, 04:36 PM
Last Post: hachem
  “Cannot connect to 8822 (connection timed out)" Ikbal 0 1,990 12-08-2014, 11:38 PM
Last Post: Ikbal

Forum Jump:


Users browsing this thread: 1 Guest(s)