QTP Script for connecting to database using SQL Server

Check this link(script) for connecting to MS Access.

QTP Script for connecting to database using MS Access

Script for connecting to sqlserver

Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.open"provider=sqloledb.1;server=localhost;
uid=sa;pwd=;database=testdata"
rs.open"select*from emp",con
Do while not rs.eof
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop

Script for connecting to oracle

Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.open"provider=oraoledb.1;server=localhost;
uid=scott;pwd=tiger;database=testdata"
rs.open"select*from emp",con
Do while not rs.eof
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop

Data Driven Testing

SQL Queries Collection

2 comments:

Sheeraz said...

Can anyone please post a full fledged, running example of QTP extracting values from a MySQL Query? The connection string is where my script is hanging. I believe the driver value has to be something else.

Dim dbexample
Set dbexample = CreateObject("ADODB.Connection")
dbexample.ConnectionString = "driver=mysql;server=localhost;uid=uuuu;pwd=pppp;database=db123"
dbexample.Open
Set recordset = dbexample.Execute("SELECT * from myTable")
msgbox recordset.GetString


A simple script (like the one above) that is running successfully would be greatly appreciated.

-Sheeraz M.

Anonymous said...

Hi,
Thanks its very useful.....

Related Posts Plugin for WordPress, Blogger...