Thursday, October 29, 2009

TestComplete: DataBase Connection

// Sample Code to Connect to database in Test Complete

Set AConnection = ADO.CreateADOConnection
' Specify the connection string

AConnection.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=DG18\SQLEXPRESS"

' Suppress the login dialog box
AConnection.LoginPrompt = False
AConnection.Open

' Execute a simple query
Set RecSet = AConnection.Execute_("SELECT * FROM holding")
' Iterate through query results and insert data into the test log

RecSet.MoveFirst
While Not RecSet.EOF
Log.Message RecSet.Fields("Script").Value
RecSet.MoveNext
Wend



AConnection.Close

1 comment:

  1. Thats cool, but what should i do if i am connecting to a remote DB and it needs to fill the user name and password?

    ReplyDelete

I welcome your comment, will respond and post it at the earliest:)