This Blog is for Newbie trying to connect to IBM DB2 database for database testing using QTP.
Connecting to IBM DB2 in QTP is a 2 Step Process.
Step 1 : Get IBM DB2 ODBC Driver
Step 2 : Write the Code (Get Connection String to be exact).
Let me elaborate the process in detail.
STEP 1 : Get IBM DB2 ODBC Driver.
Unlike Java where drivers are available for free, here IBM drivers are licensed. I don’t know why they did it that way. Follow the below procedure.
Check whether IBM DB2 ODBC Driver is installed on your system.
Go to Control Panel > Administrative Tools > Data Sources (ODBC)
Go to Drivers Tab > Check whether you have IBM DB2 ODBC DRIVER
STEP 2 : Write the Code (Get Connection String to be exact)
Here I have used ADODB connection object. A common way to connect various types of databases.
CODE :
*********************************************************************************************
query = "select * from SCHEMA_NAME.TABLE_NAME WHERE COLUMN NAME= 'some unique value' "
ConnectnString = "Driver={IBM DB2 ODBC DRIVER};Database=databaseName;Hostname=serverAddress;Port=portNumber; Protocol=TCPIP;Uid=userName;Pwd=passWord;"
'ConnectnString = "Driver={ IBM DB2 ODBC DRIVER - DB2COPY1};Database=databaseName;Hostname=serverAddress;Port=portNumber; Protocol=TCPIP;Uid=userName;Pwd=passWord;"
Set connectionOBJ = CreateObject("ADODB.Connection")
Set recordSetOBJ = CreateObject("ADODB.recordset")
connectionOBJ.ConnectionString = ConnectnString
connectionOBJ.Open
Set recordSetOBJ = connectionOBJ.Execute(query,,adExecuteNoRecords)
msgbox recordSetOBJ.Fields("COLUMN_NAME")
*********************************************************************************************
I have commented Driver={ IBM DB2 ODBC DRIVER - DB2COPY1} use this connection String if Driver={IBM DB2 ODBC DRIVER} fails
You might encounter the below Errors :
Error#1 : Specified DRIVER could not be loaded due to System Error 5
It means you don’t have access privileges to C:\Program Files\IBM\SQLLIB folder or its subfolders. Get the access from System Administrator.
Error#2 : Catastrophic Failure at connectionOBJ.Open
This is a weird error and to fix this you need to exit QTP and delete [or rename] the file :
C:\Program Files\HP\QuickTest Professional\bin\ QtPro.exe.local
Then restart your system.
The above file is of no use unless you are working with LoadRunner. And somehow this conflicts with the driver.
That is it. Feel free to comment
Connecting to IBM DB2 in QTP is a 2 Step Process.
Step 1 : Get IBM DB2 ODBC Driver
Step 2 : Write the Code (Get Connection String to be exact).
Let me elaborate the process in detail.
STEP 1 : Get IBM DB2 ODBC Driver.
Unlike Java where drivers are available for free, here IBM drivers are licensed. I don’t know why they did it that way. Follow the below procedure.
Check whether IBM DB2 ODBC Driver is installed on your system.
Go to Control Panel > Administrative Tools > Data Sources (ODBC)
Go to Drivers Tab > Check whether you have IBM DB2 ODBC DRIVER
- If you don’t have it then there are two costly ways to do it. Buy IBM DB2 ODBC DRIVER from IBM, if you are self user / if you are working in a company then ask you Project Managers to get it installed from Maintenance Team.
- Install IBM DB2 Client software . This is also a licensed software .
- Source : http://www-01.ibm.com/support/docview.ws...wg21418043
- Make sure your user account have ‘Read & Execute’ permissions to C:\Program Files\IBM\SQLLIB to this folder.
- Try navigating to this folder you’ll understand. If you do not have access privileges contact your system Administrator and get Full Control of this and its subfolders.
STEP 2 : Write the Code (Get Connection String to be exact)
Here I have used ADODB connection object. A common way to connect various types of databases.
CODE :
*********************************************************************************************
query = "select * from SCHEMA_NAME.TABLE_NAME WHERE COLUMN NAME= 'some unique value' "
ConnectnString = "Driver={IBM DB2 ODBC DRIVER};Database=databaseName;Hostname=serverAddress;Port=portNumber; Protocol=TCPIP;Uid=userName;Pwd=passWord;"
'ConnectnString = "Driver={ IBM DB2 ODBC DRIVER - DB2COPY1};Database=databaseName;Hostname=serverAddress;Port=portNumber; Protocol=TCPIP;Uid=userName;Pwd=passWord;"
Set connectionOBJ = CreateObject("ADODB.Connection")
Set recordSetOBJ = CreateObject("ADODB.recordset")
connectionOBJ.ConnectionString = ConnectnString
connectionOBJ.Open
Set recordSetOBJ = connectionOBJ.Execute(query,,adExecuteNoRecords)
msgbox recordSetOBJ.Fields("COLUMN_NAME")
*********************************************************************************************
I have commented Driver={ IBM DB2 ODBC DRIVER - DB2COPY1} use this connection String if Driver={IBM DB2 ODBC DRIVER} fails
You might encounter the below Errors :
Error#1 : Specified DRIVER could not be loaded due to System Error 5
It means you don’t have access privileges to C:\Program Files\IBM\SQLLIB folder or its subfolders. Get the access from System Administrator.
Error#2 : Catastrophic Failure at connectionOBJ.Open
This is a weird error and to fix this you need to exit QTP and delete [or rename] the file :
C:\Program Files\HP\QuickTest Professional\bin\ QtPro.exe.local
Then restart your system.
The above file is of no use unless you are working with LoadRunner. And somehow this conflicts with the driver.
That is it. Feel free to comment
No comments:
Post a Comment