How to connect to the Database from QTP?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to record application running on the Virtual machine?

636


How to use Environment parameterization? Explain with an example.

1477


How to perform cross platform testing and cross browser testing using qtp? Can you explain giving some example?

542


Where to use Property Let, Property Get, Property Set in UFT

370


can i compare two databases using QTP ?

1875






Can anybody let me know how to test the Drag and drop feature of the column in a .net application...eg..i hav to test the drag and drog feature of a table(swftable) in a application..plze help!!

1747


Explain the views in the QTP GUI?

615


What is quicktest professional window?

555


When QTP object wait time is 10 seconds, and in test script wait time is 5 seconds and in function library wait time is 2 seconds how much time does the wait occur? or which is given priority.

1624


How to use output values in qtp ?

554


Hello, Is there any way to send the test results in html format (or any other) by email using outlook after the test run ends? thank you in advance

1738


What are the ordinal identifiers in web page?

633


Can we call qtp test from another test using scripting. Suppose there are 4 tests and I want to call these tests in a main script. Is this possible in qtp?

649


Define Error Pane of UFT?

686


What is the file extension of the code file in qtp?

560