How to connect database by using QTP tooland also how can we create 'dsn'.do we create 'dsn'

Showing Answers 1 - 3 of 3 Answers

Raghu

  • Dec 27th, 2006
 

Hi,

First if you want to create any DSN

follow the steps Go To Administrative Tools->Data Sources->click Add-> select the type of driver and rest follow the wizards

for connecting the DSN using QTP

Dim DBObj,Rec,DBRS,Results

DBObj=createobject("ADODB.connection")

set Rec=DBObj.open("DSN=DSN_Name")

DBRS=createobject("ADODB.recordset")

set Results=DBRS.execute("Select * from table_name")

msgbox Results.fields(0)

  Was this answer useful?  Yes

reddy

  • Jan 23rd, 2007
 

hi friend,

to create a dsn goto control pannel->performance and maintinance->administrative tools->data sources

in that add your desired data driver, click on ok

to connect to a data base

dim con,rs

con=createobject("adodb.connection")

rs=createobject("adodb.recordset")

con.open "provider=sqloledb;database=company;user id=sa;password=;server=server1"

rs.open "select * from emp",con

do

msgbox rs(0) & rs(1) & rs(2) & ............

rs.movenext

loop while rs.eof

  Was this answer useful?  Yes

sushgarg

  • Nov 6th, 2009
 

You can use the Dynamic DSN Query string which will be machine independent
e.g.
' Count the rows for returned recordset
    Dim oConn, oRS, iCounter,sWorkBook,sQuery
    Set oConn = CreateObject("ADODB.Connection")
    Set oRS = CreateObject("ADODB.RecordSet")
    oConn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & sWorkBook & ";Readonly=True"
    oRS.Open sQuery, oConn, 3, 3, 1
    iCounter=0
    While oRS.EOF = False
        iCounter=iCounter+1
        oRS.MoveNext
    Wend
    Set oRS=Nothing
    oConn.Close
    Set oConn=Nothing

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.