How to connect to Database using QTP or vbscripting
2 posters
Page 1 of 1
Re: How to connect to Database using QTP or vbscripting
The following sample code (or some form of it) is readily available in most of the QTP or VBScript help forums, so don’t despair if I’m not giving you exactly what you need.
Dim objConn ' As an ADODB Connection object
Dim objRecSet ' As an ADODB Recordset object
Dim strConn ' As a connection string
Dim strQuery ' As a SQL query
' Create the connection and recordset objects
Set objConn = CreateObject("ADODB.Connection")
Set objRecSet = CreateObject("ADODB.Recordset")
' Create the connection string
strConn = "DRIVER={Oracle in instantclient10_2};DBQ=<YourTNSName>;UID=<YourUsername>;PWD=<YourPassword>"
' Define the SQL query
strQuery = "SELECT * FROM <YourDatabaseTable>"
' Open the connection
objConn.Open strConn
' Retrieve data using SQL query
objRecSet.Open strQuery, objConn
' Do something with the data here
' Close the connection (also closes the recordset and destroys both)
objConn.Close
Sample TNSNAMES.ORA Content:
YourTNSName =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <YourServerNameOrIP>)(PORT = <YourPortOrDefault1521>))
)
(CONNECT_DATA =
(SID = <YourDBSID>)
(SERVER = DEDICATED)
)
)
Dim objConn ' As an ADODB Connection object
Dim objRecSet ' As an ADODB Recordset object
Dim strConn ' As a connection string
Dim strQuery ' As a SQL query
' Create the connection and recordset objects
Set objConn = CreateObject("ADODB.Connection")
Set objRecSet = CreateObject("ADODB.Recordset")
' Create the connection string
strConn = "DRIVER={Oracle in instantclient10_2};DBQ=<YourTNSName>;UID=<YourUsername>;PWD=<YourPassword>"
' Define the SQL query
strQuery = "SELECT * FROM <YourDatabaseTable>"
' Open the connection
objConn.Open strConn
' Retrieve data using SQL query
objRecSet.Open strQuery, objConn
' Do something with the data here
' Close the connection (also closes the recordset and destroys both)
objConn.Close
Sample TNSNAMES.ORA Content:
YourTNSName =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <YourServerNameOrIP>)(PORT = <YourPortOrDefault1521>))
)
(CONNECT_DATA =
(SID = <YourDBSID>)
(SERVER = DEDICATED)
)
)
How to connect to Database using QTP or vbscripting
I have to connect to database using QTP or vbscripting, to fetch some data and use the data it in my code.
Can anyone please help me on this?
Thanks in advance.
Can anyone please help me on this?
Thanks in advance.
ITSG- Posts : 1
Points : 3
Reputation : 0
Join date : 2012-05-03
Age : 41
Location : Hyderabad
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum