Exforsys
+ Reply to Thread
Results 1 to 2 of 2

QTP script problem

This is a discussion on QTP script problem within the Software Testing forums, part of the Testing category; Hello to all, I have a doubt in QTP script. How can we call database in QTP? Option Explicit Dim ...

  1. #1
    deepjyoti is offline Junior Member Array
    Join Date
    Sep 2008
    Location
    chennai
    Answers
    1

    QTP script problem

    Hello to all,

    I have a doubt in QTP script. How can we call database in QTP?



    Option Explicit
    Dim con,rs
    Set con=createobject("adodb.connection")
    Set rs=createobject("adodb.recordset")
    con.open"provider=sqloledb.1; server=.??????
    uid=sa;pwd=sa;database=testdata"
    rs.open"select*from emp",con
    Do while not rs.eof
    VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
    VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
    VbWindow("Form1").VbButton("ADD").Click
    rs.movenext
    Loop

    Please check above script is there any problem. I could not understand about server option on the 5th line of the script ...Please explain in detail?


  2. #2
    kalyansantosh is offline Member Array
    Join Date
    Feb 2007
    Location
    Hyderabad
    Answers
    82
    Database Connection


    Function Getconnection()
    Const adOpenStatic = 3

    Const adLockOptimistic = 3

    Const adUseClient = 3

    Set objCon=CreateObject("ADODB.Connection")

    Set objRec=CreateObject("ADODB.Recordset")

    objCon.Open "Driver={MySQL ODBC 3.51 Driver};SERVER=120.10.1.215;DATABASE=name;user id=root;password=root; Pooling=True"

    objRec.CursorLocation = adUseClient

    objRec.Open "Select Max(Productid) as Productid from Products",objCon,adOpenStatic,adLockOptimistic

    While(Not objRec.EOF)
    val = objRec.Fields.Item("Productid")
    MsgBox(val)
    objRec.MoveNext
    Wend
    objRec.Close

    objCon.Close

    Set objRec=Nothing

    Set objCon=Nothing

    End Function






    Explaination



    objCon.Open "Driver={MySQL ODBC 3.51 Driver};SERVER=120.10.1.215;DATABASE=name;user id=root;password=root; Pooling=True"



    here we are opening the connection
    fst we have to mention driver, Server name,database name, username and password
    after identifying the qtp


    if any clarifications please mail me kalyansantosh@gmail.com

    Last edited by kalyansantosh; 09-21-2008 at 04:07 AM. Reason: Editing

Latest Article

Network Security Risk Assessment and Measurement

Read More...