Tuesday, February 2, 2016

Connecting to Oracle Database from VB Script

Recently while trying to connect to an Oracle DB using VBScript within TestComplete, I ran across the error "Oracle client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Versi on 7.3.3 or later client software installation."

I was using the following code:

FUNCTION test_sql
DIM ado_Connection, ado_RecordSet
SET ado_Connection = CreateObject("ADODB.Connection")

SET ado_RecordSet = CreateObject("ADODB.Recordset")
Dim strSQLQuery: strSQLQuery = "SELECT * FROM ABC where rownum < '2'"
Dim strDBDesc: strDBDesc = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=11.1.111.111)(PORT=1521)))(CONNECT_DATA=(SID=DB_QA)))"
Dim strConnection:strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & strDBDesc & ";User ID=uid;Password=pwd;"
 

ado_Connection.ConnectionString = strConnection

ado_RecordSet.Open strSQLQuery, ado_Connection, adOpenForwardOnly, adLockReadOnly, adCmdText
 

'Process Recordset obtained

END FUNCTION


These are the steps I used to 'finally' (phew!) get it to work.

TestComplete uses 32 bit ODBC libraries.

1) Download and unzip to any directory
 ODAC121024Xcopy_32bit.zip

2) Open the readme.html and follow instructions to install 'all' components and then add the the install directory and the install directory's bin subdirectory to the system PATH environment variable.

3) Open the 32 bit ODBC data source administrator from 'C:\Windows\SysWOW64' (file:odbcad32.exe)

4) Click Add

5) Find 'Microsoft ODBC for Oracle' and it.

Run the above code. It works









No comments:

Post a Comment