How to connect to Database using QTP or vbscripting

View previous topic View next topic Go down

Re: How to connect to Database using QTP or vbscripting

Post  Admin on Thu May 17, 2012 2:52 am

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)

)

)

Admin
Admin

Posts : 5
Points : 4
Reputation : 0
Join date : 2012-05-01

View user profile http://qtpelearning.bigforumpro.com

Back to top Go down

How to connect to Database using QTP or vbscripting

Post  ITSG on Wed May 16, 2012 2:55 am

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.

ITSG

Posts : 1
Points : 3
Reputation : 0
Join date : 2012-05-03
Age : 35
Location : Hyderabad

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum