SlideShare a Scribd company logo
7/22/2014 QTPWorld 
Chapters 
QTPWorld News 
QTP Interview Questions 
VB Script - Part I 
VB Script - Part II 
VB Script - Part III 
Working with Files using FSO 
Excel 
Actions 
Functions 
Difference between Action 
and Function 
Parameterization 
Object Repository 
Descriptive Programming 
Regular Expression 
Error Handling & Recovery 
Scenario 
Output Values 
Checkpoints 
Database Connections 
Automation Object Model 
Synchronization 
Environment Variables 
XML 
Outlook 
Reporting Defect 
Document Object 
Model(DOM) 
Contact Us 
info@qtpworld.com 
+91- 080-42711061 
Database Connections 
Login | Search QTPWorld.com 
What is adodb connection ? 
The ADO(ActiveX Data Objects) Connection object is used to create a connection to a data source. Through this connection, 
you can access and manipulate a database. 
What is adodb recordset? 
The ADO Recordset object is used to hold a set of records from a database table.To be able to read database data, the data 
should be loaded into a recordset. 
⇒QTP Scripts for connecting to MS Access: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:mydatabase.mdb;Uid=Admin;Pwd=;" 
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 
'Release objects'Release objects 
Set rs= nothing 
Set con= nothing 
Note: The database we are using here is MS Access.Before running this script create a table in MS Acess.In the above script I used 
table called "emp" and column 'names as "v1" and "v2". "d:testdata.mdb" is path of the table which we created. The main use of this 
script is to use testdata of table(which is in ' database) in the application. In the above script we are passing values from database to 
Textboxes in Windows Application. 
⇒QTP Script for connecting to sqlserver: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
con.open"Driver={SQL Server};server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs" 
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 
'Release objects'Release objects 
Set rs= nothing 
Set con= nothing 
⇒QTP Script for connecting to oracle: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
con.open "Driver={Microsoft ODBC for Oracle};Server=QTPWorld; Uid=your_username;Pwd=your_password;" 
http://www.qtpworld.com/index.php?cid=74 1/3
7/22/2014 QTPWorld 
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 
'Release objects 
Set rs= nothing 
Set con= nothing 
⇒QTP Script for connecting to MySQL: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
con.open"Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDB;User=Uname;Password=Pwd;Option=3;" 
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 
'Release objects 
Set rs= nothing 
Set con= nothing 
⇒QTP Script for connecting to Excel: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
con.open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=C:TestStatus.xls;Readonly=True" 
rs.open "SELECT count(*) FROM [Status$] where Status = 'Failed' ",con 
Msgbox rs(0) 
'Release objects 
Set rs= nothing 
Set con= nothing 
⇒QTP Script for connecting to Sybase: 
Option Explicit 
Dim con,rs 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset") 
' Open a session to the database 
con.open"Driver={SYBASE SYSTEM 11};Srvr=myServerAddress;Uid=Uname;Pwd=Pwd;Database=myDataBase;" 
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 
'Release objects 
Set rs= nothing 
Set con= nothing 
http://www.qtpworld.com/index.php?cid=74 2/3
7/22/2014 QTPWorld 
Copyright QTPWorld.com 2013 Home | Demo videos | Students | Training | FAQ's | Feedback | About Us Designed By WebZone 
http://www.qtpworld.com/index.php?cid=74 3/3

More Related Content

PDF
VBA API for scriptDB primer
PPS
MongoDB crud
PPT
Introduction to MongoDB
PDF
JavaScript client API for Google Apps Script API primer
PDF
An introduction to MongoDB
PDF
Spray Json and MongoDB Queries: Insights and Simple Tricks.
PPTX
Databases in Qt
PDF
Assist9 bmis
VBA API for scriptDB primer
MongoDB crud
Introduction to MongoDB
JavaScript client API for Google Apps Script API primer
An introduction to MongoDB
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Databases in Qt
Assist9 bmis

What's hot (20)

PPTX
Google apps script database abstraction exposed version
PPTX
Dbabstraction
KEY
MongoDB Java Development - MongoBoston 2010
PPTX
Mejores Practicas en SQL Server - Seguridad, Conectividad y CLR
PPTX
Javascript
PDF
MongoDB.local Paris Keynote
DOC
Database c# connetion
PPTX
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
PDF
Fetch data from form
PPTX
Mongo db queries
PPT
NoSQL - "simple" web monitoring
PDF
Google apps script
PDF
Full metal mongo
PDF
Auto-GWT : Better GWT Programming with Xtend
PDF
Advanced Swift Generics
PPTX
Thinking in Sequences - Streams in Node.js & IO.js
PPTX
Goa tutorial
PDF
CHOReOS Web Services FISL Conference Brazil 2012
PDF
Quirrel & R for Dummies
PPTX
Sydney Python Presentation (Feb 2010) - Tracking Large Metallic Objects / Goo...
Google apps script database abstraction exposed version
Dbabstraction
MongoDB Java Development - MongoBoston 2010
Mejores Practicas en SQL Server - Seguridad, Conectividad y CLR
Javascript
MongoDB.local Paris Keynote
Database c# connetion
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
Fetch data from form
Mongo db queries
NoSQL - "simple" web monitoring
Google apps script
Full metal mongo
Auto-GWT : Better GWT Programming with Xtend
Advanced Swift Generics
Thinking in Sequences - Streams in Node.js & IO.js
Goa tutorial
CHOReOS Web Services FISL Conference Brazil 2012
Quirrel & R for Dummies
Sydney Python Presentation (Feb 2010) - Tracking Large Metallic Objects / Goo...
Ad

Similar to Db connection to qtp (20)

PPT
Asp #2
PPTX
Data base connectivity and flex grid in vb
DOC
Qtp script to connect access database
PDF
Oracle to vb 6.0 connectivity
PPTX
Ado object
PPT
AVB202 Intermediate Microsoft Access VBA
DOCX
Inventory program in mca p1
PPT
vishual basic data base Pankaj
PPT
VB6 Using ADO Data Control
PPT
Using ADO Data Control
PDF
Visual basic databases
PPT
ADO Controls - Database Usage from Exploring MS Visual Basic 6.0 Book
DOCX
โครงการ 5 บท
DOCX
โครงการ 5 บท
PPTX
ADO.NET -database connection
PPT
ADO CONTROLS - Database usage
DOC
Adodb Scripts And Some Sample Scripts[1]
DOC
Adodb Scripts And Some Sample Scripts[1]
PPS
VISUAL BASIC .net data accesss vii
PDF
Bt0082 visual basic2
Asp #2
Data base connectivity and flex grid in vb
Qtp script to connect access database
Oracle to vb 6.0 connectivity
Ado object
AVB202 Intermediate Microsoft Access VBA
Inventory program in mca p1
vishual basic data base Pankaj
VB6 Using ADO Data Control
Using ADO Data Control
Visual basic databases
ADO Controls - Database Usage from Exploring MS Visual Basic 6.0 Book
โครงการ 5 บท
โครงการ 5 บท
ADO.NET -database connection
ADO CONTROLS - Database usage
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
VISUAL BASIC .net data accesss vii
Bt0082 visual basic2
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
Understanding_Digital_Forensics_Presentation.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Db connection to qtp

  • 1. 7/22/2014 QTPWorld Chapters QTPWorld News QTP Interview Questions VB Script - Part I VB Script - Part II VB Script - Part III Working with Files using FSO Excel Actions Functions Difference between Action and Function Parameterization Object Repository Descriptive Programming Regular Expression Error Handling & Recovery Scenario Output Values Checkpoints Database Connections Automation Object Model Synchronization Environment Variables XML Outlook Reporting Defect Document Object Model(DOM) Contact Us info@qtpworld.com +91- 080-42711061 Database Connections Login | Search QTPWorld.com What is adodb connection ? The ADO(ActiveX Data Objects) Connection object is used to create a connection to a data source. Through this connection, you can access and manipulate a database. What is adodb recordset? The ADO Recordset object is used to hold a set of records from a database table.To be able to read database data, the data should be loaded into a recordset. ⇒QTP Scripts for connecting to MS Access: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:mydatabase.mdb;Uid=Admin;Pwd=;" 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 'Release objects'Release objects Set rs= nothing Set con= nothing Note: The database we are using here is MS Access.Before running this script create a table in MS Acess.In the above script I used table called "emp" and column 'names as "v1" and "v2". "d:testdata.mdb" is path of the table which we created. The main use of this script is to use testdata of table(which is in ' database) in the application. In the above script we are passing values from database to Textboxes in Windows Application. ⇒QTP Script for connecting to sqlserver: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") con.open"Driver={SQL Server};server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs" 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 'Release objects'Release objects Set rs= nothing Set con= nothing ⇒QTP Script for connecting to oracle: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") con.open "Driver={Microsoft ODBC for Oracle};Server=QTPWorld; Uid=your_username;Pwd=your_password;" http://www.qtpworld.com/index.php?cid=74 1/3
  • 2. 7/22/2014 QTPWorld 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 'Release objects Set rs= nothing Set con= nothing ⇒QTP Script for connecting to MySQL: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") con.open"Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDB;User=Uname;Password=Pwd;Option=3;" 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 'Release objects Set rs= nothing Set con= nothing ⇒QTP Script for connecting to Excel: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") con.open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=C:TestStatus.xls;Readonly=True" rs.open "SELECT count(*) FROM [Status$] where Status = 'Failed' ",con Msgbox rs(0) 'Release objects Set rs= nothing Set con= nothing ⇒QTP Script for connecting to Sybase: Option Explicit Dim con,rs Set con=createobject("adodb.connection") Set rs=createobject("adodb.recordset") ' Open a session to the database con.open"Driver={SYBASE SYSTEM 11};Srvr=myServerAddress;Uid=Uname;Pwd=Pwd;Database=myDataBase;" 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 'Release objects Set rs= nothing Set con= nothing http://www.qtpworld.com/index.php?cid=74 2/3
  • 3. 7/22/2014 QTPWorld Copyright QTPWorld.com 2013 Home | Demo videos | Students | Training | FAQ's | Feedback | About Us Designed By WebZone http://www.qtpworld.com/index.php?cid=74 3/3