QTP Forum - WitWorks
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to connect to Database using QTP or vbscripting

2 posters

Go down

How to connect to Database using QTP or vbscripting Empty Re: How to connect to Database using QTP or vbscripting

Post  Admin 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

https://qtpelearning.board-directory.net

Back to top Go down

How to connect to Database using QTP or vbscripting Empty How to connect to Database using QTP or vbscripting

Post  ITSG 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 : 41
Location : Hyderabad

Back to top Go down

Back to top


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