how we connect oracle or sql data server database to qtp

Answer Posted / kiran

Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset


'Defines the connection string for the Connection. Here we have used fields
'Provider, Data Source and Mode to assign values to the properties
' conConnection.Provider and conConnection.Mode

conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "database.mdb;Mode=Read|Write"


'Define the location of the cursor engine, in this case we are opening an Access database
'and adUseClient is our only choice.

conConnection.CursorLocation = adUseClient


'Opens our connection using the password "Admin" to access the database. If there was no password
'protection on the database this field could be left out.

conConnection.Open


'Defines our command object

' .ActiveConnection tells the command to use our newly created command object.
' .CommandText tells the command how to get the data, in this case the command
' will evaluate the text as an SQL string and we will return all
' records from a table called tabTestTable
' .CommandType tells the command to evaluate the .CommandText property as an SQL string.

With cmdCommand
.ActiveConnection = conConnection
.CommandText = "SELECT * FROM tabTestTable;"
.CommandType = adCmdText
End With

'Defines our RecordSet object.

' .CursorType sets a static cursor, the only choice for a client side cursor
' .CursorLocation sets a client side cursor, the only choice for an Access database
' .LockType sets an optimistic lock type
' .Open executes the cmdCommand object against the data source and stores the
' returned records in our RecordSet object.

With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmdCommand
End With

'Firstly test to see if any records have been returned, if some have been returned then
'the .EOF property of the RecordSet will be false, if none have been returned then the
'property will be true.

If rstRecordSet.EOF = False Then

'Move to the first record

rstRecordSet.MoveFirst

'Lets move through the records one at a time until we reach the last record
'and print out the values of each field

Do

'Access the field values using the fields collection and print them to a message box.
'In this case I do not know what you might call the columns in your database so this
'is the safest way to do it. If I did know the names of the columns in your table
'and they were called "Column1" and "Column2" I could reference their values using:

' rstRecordSet!Column1
' rstRecordSet!Column2


MsgBox "Record " & rstRecordSet.AbsolutePosition & " " & _
rstRecordSet.Fields(0).Name & "=" & rstRecordSet.Fields(0) & " " & _
rstRecordSet.Fields(1).Name & "=" & rstRecordSet.Fields(1)

'Move to the next record

rstRecordSet.MoveNext
Loop Until rstRecordSet.EOF = True

'Add a new record

With rstRecordSet
.AddNew
.Fields(0) = "New"
.Fields(1) = "Record"
.Update
End With

'Move back to the first record and delete it

rstRecordSet.MoveFirst
rstRecordSet.Delete
rstRecordSet.Update


'Close the recordset

rstRecordSet.Close
Else
MsgBox "No records were returned using the query " & cmdCommand.CommandText
End If

'Close the connection

conConnection.Close

'Release your variable references

Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
End Sub

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to replay a script in qtp?

612


Hoe can we do retesting using functions please give the code for it using login page

1565


How many lines of code in each script of QTP?

4036


What is the use of an object spy tool in qtp?

557


What is the limitation to XML Checkpoints?

1601






I hav installed QTP8.2, im working on webapplication, while running the script giving error msg like "QTPro.exe generated errors and will be closed by windows. You will restart the program. An error log is being created". Pls anybody what is the problem, what i have to do for this? Thanks...

1715


Qtp has been installed on my pc but recently ON opening it is giving this error PLEASE REPLY IT IS URGENT IT WAS WORKKING FINE QTPRO.EX THE instruction at "0x7.. ...". referenced memory at "0000....The memory could not be read... Awaiting QTP XPERTS REPly URGENT

2053


What is RTM (require ment tracebulity marix) fromate?

1527


hi to all, i need a code.. in flight application 1.i need to login first then i need to insert 3 new orders... 2.i have to log out 3.i have to login again with different user 4.need to insert 2 new orders 5.then need to log out 6.then again login with different user 7.3 new orders create and log out 8.but we hv to do this using data table and actions please help me

1756


What is the meaning Work bench?

1758


This is a question thats generally asked in every QTP interview. What were the problems that you faced during automation and how did you resolve them?

1463


Can I change properties of a test object?

620


How often were they executed?

2034


Hi I have exp in manual testing and planning to move in automation testing qtp(9.2).So can help me how to automate customer relationship management tool using qtp and vb script this tool already developed so how can I test it whatever maintaining by development team like documents,various options just give the whole life cycle thanks in advance

1539


How do you synchronization point through DP?

595