Micro Focus QTP (UFT) Forums
Creating Connection string for DB2 - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Creating Connection string for DB2 (/Thread-Creating-Connection-string-for-DB2)



Creating Connection string for DB2 - sqadri - 04-13-2012

Hi,

I am trying to craete a cnnection string for DB2 but cannot it working. Here are the functions I am suing. Could someone please tell me what is wrong. I believe it is the data Source but dont know what that is.

Code:
Function getConnection ()
    On Error Resume Next
    Dim oConnection,ConnectionString
    ConnectionString ="jdbc:db2://ny-c-012:50000/hztest" '"Provider=Microsoft.Jet.OLEDB.4.0"
    Data Source="DB2LUW"'"hztest"'C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight32.mdb"
    User Id="db2admin", Password="Ibmtest1"
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open ConnectionString
    Set getConnection = oConnection
End Function

Function CheckConnection
   Dim MyConnString, MyConnection
   Set MyConnection = getConnection
   If MyConnection.Errors.Count = 0 Then
       Print "Database Connected"
    else
        Print "Database Failed"
   End If
End Function

Thanks,
Sqadri


RE: Creating Connection string for DB2 - sshukla12 - 04-13-2012

Hi,

Could u please try this:


Code:
Function GetDataFromBase(DNS,UID,PWD,QUERY)

    Set MyConnection = CreateObject("ADODB.Connection")
    Set myrecordset = CreateObject("ADODB.recordset")

    MyConnection.ConnectionString ="DSN=" & DNS  & "; UID=" & UID & ";PWD=" & PWD

    MyConnection.Open
    Set myrecordset = MyConnection.Execute(QUERY)
    GetDataFromBase = myrecordset(0)
    MyConnection.Close

End Function

Let me know if its work's 4 u.

Regards,
Sankalp