Troubleshooting
Problem
This document describes how an IBM Rational Robot GUI script can connect to an IBM DB2, Microsoft SQL Server or Oracle database using Active X data objects.
Resolving The Problem
To connect to an IBM DB2, Microsoft SQL Server or Oracle database using Active X data objects:
- Ensure that an ODBC connection exists for the database. To verify this
- Click the Start Button and select Settings > Control Panel > Administrative Tools > Data Sources (ODBC)
- There should be a data source there that uses the driver
- "IBM DB2 ODBC DRIVER" for an IBM DB2 database
- "SQL Server" for a Microsoft SQL Server database, or
- "Oracle ODBC Driver" for an Oracle database
- Declare and instantiate 2 variables of type "object" to represent instances of the ADOB.Connection and ADOB.Recordset classes, for example:
Dim conn As Object
Dim rs As Object
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADPDB.Recordset")
- Call the open method of the ADODB.Connection object:
conn.open "%ODBC DATA SOURCE NAME%", "%DB LOGIN%", "%PASSWORD%"
Replace the values above with
%ODBC DATA SOURCE NAME% with the Data source from Step 1
%DB LOGIN% with the login used to access the database
%PASSWORD%
- Call the "open" method of the ADODB.Recordset object:
rs.open "%SQL STATEMENT%", conn
Replace the value of %SQL STATEMENT% with a valid SQL statement.
- Close the ADODB.Recordset and ADODB.Connection objects:
rs.close
conn.close
Here is an example script:
Sub Main
- 'Declare variables to hold new objects
Dim conn as Object 'Variable for ADODB.Connection object
Dim rs as Object 'Variable for ADODB.Recordset object
'Instantiate variables
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
'Open connection to DB2 database
conn.open "db_DSN", "username", "password"
'Open connection to recordset
rs.open "select name from master_dbs where master_dbid = 16777220;", conn
'Close recordset and connection objects
rs.close
conn.close
End Sub
[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"General information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2002;2002.05.00;2002 Release 2;2002.05.20;2003;2003.06.00;2003.06.12","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21179062