How to connect to the Database from QTP?

Answers were Sorted based on User's Feedback



How to connect to the Database from QTP?..

Answer / murali raju

Through scripting this is way to connect the database
Example:-

set conn=Createobject("ADODB.Connection")
Srvname="Driver={Microsoft ODBC for
Oracle}:Server=DBserver,UID=Sa,Password=sa"
conn.open Srvname
Set Rec = CreateObject("ADODB.Recordset")
SQL="select * from Users"
Rec.open SQL ,conn
Username=Rec.fields("employee name")
Msgbox Username

Is This Answer Correct ?    86 Yes 20 No

How to connect to the Database from QTP?..

Answer / murali raju

Microsoft ADO (ActiveX Data Objects) is a Component object
model object for accessing data sources.The ADO Recordset
object is used to hold a set of records from a database
table. A Recordset object consist of records and columns
(fields).
In ADO, this object is the most important and the one used
most often to manipulate data from a database.

Srvname is a connection string.if u already installed
oracle in your system..using that path u can connect oracle
database...if u dont have oracle give the conncetion string
path..whatever connection string created used in database
checkpoint by
default...Example:DSN=QT_Flight32;DBQ=C:\Program
Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight32.mdb;Driver=C:\WINDO
WS\system32\odbcjt32.dll;DriverId=281;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;

Is This Answer Correct ?    39 Yes 6 No

How to connect to the Database from QTP?..

Answer / ramireddy

Thru Self scripting:
set conn=createobject("adodb.connection")
set rs=createobject("adodb.recordset")
' Oracle client is required to be installed on your box
conn.open= "Provider=OraOLEDB.Oracle.1;Password=***;Persist
Security Info=True;User ID=****;SERVER=****;Data
Source=****;DBQ=****;"
sql="your sql"
rs.open sql,conn

rs.close
set rs=nothing

conn.close
set conn=nothing

Is This Answer Correct ?    25 Yes 6 No

How to connect to the Database from QTP?..

Answer / sandipgami84

Dim ObjCon, ObjResult, ObjSQL
set ObjCon=Createobject("ADODB.Connection")
ObjCon.ConnectionString("DSN= ,UID= ,PWD= ")
ObjSQL="SELECT * FROM Emp"
ObjCon.Open()
ObjResult=ObjCon.Execute(ObjSQL)
ObjCon.Close()
ObjResult=Nothing

whtever ur data stored in ObjResult variable

Is This Answer Correct ?    31 Yes 13 No

How to connect to the Database from QTP?..

Answer / manohar

Dim con,rs
set con=createobject("ADODB.Connection")
set rs=createobject("ADODB.Recordset")
con.provider="Microsoft.jet.oledb.4.o"
con.open"Path of the database"
rs.open "select * (table name),con

Is This Answer Correct ?    27 Yes 10 No

How to connect to the Database from QTP?..

Answer / ss

Dim objConnection
'Set Adodb Connection Object
Set objConnection = CreateObject("ADODB.Connection")
Dim objRecordSet

'Create RecordSet Object
Set objRecordSet = CreateObject("ADODB.Recordset")

Dim DBQuery 'Query to be Executed
DBQuery = "Select NAME from dbo.EMPLOYEE where AGE = 29"

'Connecting using SQL OLEDB Driver
objConnection.Open "Provider=sqloledb.1;Server=.SQLEXPRESS;User Id=sa;Password=Password123;Database=Trial"

'Execute the Query
objRecordSet.Open DBQuery,objConnection

'Return the Result Set
Value = objRecordSet.fields.item(0)
msgbox Value

' Release the Resources
objRecordSet.Close
objConnection.Close

Set objConnection = Nothing
Set objRecordSet = Nothing

Is This Answer Correct ?    2 Yes 0 No

How to connect to the Database from QTP?..

Answer / surendra adapa

For Sql-Server:
"provider=SQLOLEDB;Server=servername;Databae=dbname;Userid= ;Password= :"
or
"provider=SQLOLEDB;Server=servername;Databae=dbname;Trusted-Connection=yes;" (windows Authentication)

For MS-Access:
"provider=Microsoft.Jet.OLEDB.4.0;DataSoure=Path;uid= ;pwd= ;"

Is This Answer Correct ?    3 Yes 2 No

How to connect to the Database from QTP?..

Answer / manjula b

Set odb=createobject("ADODB.connection")
Strpath="c:usershappydesktopdesktop31database2.mdb"
Odb.connection string="provider=microsoft.jet.oledb.4.0;datasource="&strpath
Odb.open
Sql1="select *from employees"
Set orec=odb.execute(sql1)
Dountil orec.eof=true
Print orec.fields("employee name")
Orec.move next
Loop
Odb.close

Is This Answer Correct ?    0 Yes 0 No

How to connect to the Database from QTP?..

Answer / srikanth

Thanks murali...
What is 'ADODB', 'Recordset' and wht we have to give
in 'Srvname'?

Is This Answer Correct ?    10 Yes 25 No

How to connect to the Database from QTP?..

Answer / francis

connect to database using database checkpoint,database
output value(connection string is needed)

Is This Answer Correct ?    21 Yes 46 No

Post New Answer

More QTP Interview Questions

can QTP works on LINUX platfom

2 Answers  


Is it possible to change the name of a test object. I mean when we are recording the script for an object (for Ex: Username is a text field which has value "Babu",i am recording that). Then the Name of the object will become "Babu" in object repository. If i want to change "babu" as "xxxxx" .. is it possible to do? Pls help me in this .. if you didn't understand the question, pls let me know.

4 Answers  


I Scheduled a QTP Script on remote desktop. Script is going to failure,when remote desktop connection fails.I have to open my remote desktop untile the scripts exection completes. If I disconnect my remote desktop connection, script is going to fail. Could you please any assist in this?

2 Answers  


Hoe to generate all numbers in between to numbers suppose all numbers in between 1 to 100 using vbscript give me code

2 Answers  


How does QTP identifies the object in the application

6 Answers   Convergys,






Can anyone explain about Keyword driven framework in detail and how to use it in case of any project

4 Answers  


what is key word driven frame work ? why it is called like that ? what is the diference between keyword driven and data driven frame work ?

0 Answers  


how to record a word doc using qtp i.e open a word doc,type something and save the doc can someone send me the code.

3 Answers  


suppose u hav a dialog or window which contains 10 buttons with same name & value. now how to check each button? i.e. how qtp indetifies these objects separately?

2 Answers  


What is qtpro? What is quick test pro? What is a quick test professional?

0 Answers  


How to add multiple values in rows, under a single column of a run time datatable?

3 Answers   NIIT,


What are the most frequent errors you faced while executing your scripts?

4 Answers   Semantic Space,


Categories