You are on page 1of 2

Data Base Connections

Test data may be in Database, so that we should connect our test to database and retrieve the
data and use the same in test.

We should know 3 things while we dealing with database connections viz..

1. How to Connect 2. How to Establish connection 3. How to Retrieve and use the data

 For connection , we need to provide two things


1. Driver / Provider : A third party software used for establishing the connection between front end
and back end of the application.

2. Location : Location of database

Record Set : It is a temporarily location where we can store the retrieve data from data base at time.
From that temporarily location we can use the data one by one or as per requirement in our
testing.
Connection : Connects the application and database.

* We need to create Object Instances for both Record Set and Connection.

Example : For example, test data is stored as below, do write the database connection script.
Testdata.mdb
v1 v2 res
10 20 30
30 30 60
30 20 50
90 90 180
2 8 10
For MSACCESS :

‘ Dimensioning connection (con) and recordset (rs)


Dim con, rs
‘Creating object instanced for both above con and rs
‘ adodb = ActiveX Data Object Database
Set con = CreateObject (“adodb.connection”)
Set rs = CreateObject(“adodb.recordset”) These two lines never changed
Establishing
the Connection ‘ Assigning the connection with 3rd party provider i.e with microsoft
con.provider = “Microsoft.jet.oledb.4.0”
‘ Opening the database by specifying the location *
con.open “d:/automation/testdat.mdb”

‘Retrieving the data from data table


Retrieving the data rs.open “select * from info”,con

‘ by using the retrieved data , checking all the rows


‘eof : eng of file
‘ not = if the record is not end of file then go into the loop
‘ else come out from the loop
Do while not rs.eof
‘ inserting the retrived data (v1) into val1 edit field
Vbwindow(“form1”).vbEdit(“val1”).set rs.field(“v1”)
Using the Data ‘ inserting the retrived data (v2) into val2 edit field
Vbwindow(“form1”).vbEdit(“val2”).set rs.field(“v2”)
‘ clicking on ADD button
Vbwindow(“form1”).vbButton(“ADD”).click
‘ changing the focus to next row
rs.moveNext
‘ continuing the loop till eof
Loop

=============================

* For Oracle and SQL we will write both Provider name and Connection in one line and rest is same.

For Oracle
con.open “provider=oraoledb.1;server=locahost;uid=userID;pwd=password;database=database name”

For SQL
con.open “provider=sqloledb.1;server=locahost;uid=userID;pwd=password;database=database name”

-: The End :-
Pls. leave your feed back (both +ve and –ve ) at kanakadria@yahoo.co.in

You might also like