Interview Questions

WinRunner: How to connect to ORACLE Database without TNS?

Mercury WinRunner FAQ

(Continued from previous question...)

WinRunner: How to connect to ORACLE Database without TNS?

The following code would help the above problem.
tblName = getvar("curr_dir")&table;
resConnection = "";
rc = ddt_open(tblName, DDT_MODE_READ);
if (rc != E_OK)
pause("Unable to open file");
dvr = ddt_val(tblName,"DRIVERNAME");
tnsName = ddt_val(tblName,"SERVER");
user = tolower(ddt_val(tblName,"UID"));
pass = tolower(ddt_val(tblName,"PWD"));
host = ddt_val(tblName,"HOSTNAME");
port = ddt_val(tblName,"PORT");
pro = toupper(ddt_val(tblName,"PROTOCOL"));
resConnection = db_connect("session", "driver="dvr";Database="tnsName";hostname="host";port="port";protocol="pro";
uid="user"; pwd="pass";");

if (resConnection != 0)
report_msg("There is a problem in connecting to the Database = "&tnsName&", Check it please..");
report_msg("Connection to the Database is successful..");
rsEQ1 = db_execute_query("session","your database query",record_number1);
How to use this:
Assume you have saved the script in c:\winrunner as dbconnect
Save data table at same location, ie c:\winrunner as dbdetails.xls

give call to dbconnect from other script which aslo saved at same location
c:\winrunner as ==>call dbconnect("dbdetails.xls");
Because the above script is using getvar("curr_dir") function to get the current directory, looks at the same location for data table.

(Continued on next question...)

Other Interview Questions