Sunday, 6 July 2014

How to connect to sql server in QTP

Connecting to sql server is easy in QTP. In below example, we have connected to sql server.
The name of database is empdb. We have created a DSN called sqlserver.

'fetch data from database
Set db = createobject("ADODB.Connection")
'open the connection to empdb database.

db.Open "DSN=sqlserver;Database=empdb"
'create record set object

Set rst = createobject("ADODB.Recordset")
'fire the query

rst.Open "select * from emp", db,3
id = rst.RecordCount
For i=0 to id-1
'read data from table

print rst.fields(0) & rst.fields(1)
rst.Movenext
Next

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.