ADO.CreateADOConnection Method

Applies to TestComplete 12.60, last modified on September 17, 2018

Description

Creates a new IAQAADOConnection object and returns a reference to it. This object holds all information necessary to establish a connection to a database.

Declaration

ADO.CreateADOConnection()

Result An IAQAADOConnection object

Applies To

The method is applied to the following object:

Result Value

An object of the IAQAADOConnection type.

Remarks

The IAQAADOConnection object is an analogue of a Borland VCL TADOConnection object. Methods and properties are identical, with the exception that there are two variants for the VCL's Execute method, which is overloaded:

Method Description
Execute Does not return any value. Use this method if the executed command does not return records.
Execute_ Returns a Microsoft ADO Recordset object. This method is for commands that return sets of records, such as a SELECT query, or any command returning a table.

For detailed information on the underlying TADOConnection object, see VCL documentation on ADODB classes.

Example

The following example uses the Biblio.mdb file shipped with Microsoft Visual Basic. The following code illustrates the use of the IAQAADOConnection object in your script. The TestProc procedure connects to the Biblio.mdb database, executes the query and inserts results into the test log.

Note:

Using the Microsoft.Jet.OLEDB.4.0 provider requires that you run your script in the 32-bit version of TestComplete.

JavaScript

function TestProc()
{
  var AConnection, RecSet;
  // Create a Connection object
  AConnection = ADO.CreateADOConnection();
  // Specify the connection string
  AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Suppress the login dialog box
  AConnection.LoginPrompt = false;
  AConnection.Open();
  // Execute a simple query
  RecSet = AConnection.Execute_("SELECT * FROM Authors WHERE [Year Born] <> 0");
  // Iterate through query results and insert data into the test log
  RecSet.MoveFirst();
  while(! RecSet.EOF)
  {
    Log.Message(RecSet.Fields.Item("Author").Value, RecSet.Fields.Item("Year Born").Value);
    RecSet.MoveNext();
  }
  AConnection.Close();
}

JScript

function TestProc()
{
  var AConnection, RecSet;
  // Create a Connection object
  AConnection = ADO.CreateADOConnection();
  // Specify the connection string
  AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Suppress the login dialog box
  AConnection.LoginPrompt = false;
  AConnection.Open();
  // Execute a simple query
  RecSet = AConnection.Execute_("SELECT * FROM Authors WHERE [Year Born] <> 0");
  // Iterate through query results and insert data into the test log
  RecSet.MoveFirst();
  while(! RecSet.EOF)
  {
    Log.Message(RecSet.Fields("Author").Value, RecSet.Fields("Year Born").Value);
    RecSet.MoveNext();
  }
  AConnection.Close();
}

Python

def TestProc():
  # Create a Connection object
  AConnection = ADO.CreateADOConnection()
  # Specify the connection string
  AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb"
  # Suppress the login dialog box
  AConnection.LoginPrompt = False
  AConnection.Open()
  # Execute a simple query
  RecSet = AConnection.Execute_("SELECT * FROM Authors WHERE [Year Born] <> 0")
  # Iterate through query results and insert data into the test log
  RecSet.MoveFirst()
  while not RecSet.EOF:
    Log.Message(RecSet.Fields.Item["Author"].Value, RecSet.Fields.Item["Year Born"].Value)
    RecSet.MoveNext()
  AConnection.Close()

VBScript

Sub TestProc
  ' Create a Connection object
  Set AConnection = ADO.CreateADOConnection
  ' Specify the connection string
  AConnection.ConnectionString = _
  "Provider=Microsoft.Jet.OLEDB.4.0;"+ _
  "Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb"
  ' Suppress the login dialog box
  AConnection.LoginPrompt = False
  AConnection.Open
  ' Execute a simple query
  Set RecSet = AConnection.Execute_("SELECT * FROM Authors WHERE [Year Born] <> 0")
  ' Iterate through query results and insert data into the test log
  RecSet.MoveFirst
  While Not RecSet.EOF
    Log.Message RecSet.Fields("Author").Value, RecSet.Fields("Year Born").Value
    RecSet.MoveNext
  Wend
  AConnection.Close
End Sub

DelphiScript

procedure TestProc;
var
  AConnection, RecSet : OleVariant;
begin
  // Create a Connection object
  AConnection := ADO.CreateADOConnection;
  // Specify the connection string
  AConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb';
  // Suppress the login dialog box
  AConnection.LoginPrompt := False;
  AConnection.Open;
  // Execute a simple query
  RecSet := AConnection.Execute_('SELECT * FROM Authors WHERE [Year Born] <> 0');
  // Iterate through query results and insert data into the test log
  RecSet.MoveFirst;
  while not aqConvert.VarToBool(RecSet.EOF) do
  begin
    Log.Message(RecSet.Fields('Author').Value, RecSet.Fields('Year Born').Value);
    RecSet.MoveNext;
  end;
  AConnection.Close;
end;

C++Script, C#Script

function TestProc()
{
  var AConnection, RecSet;
  // Create a Connection object
  AConnection = ADO["CreateADOConnection"]();
  // Specify the connection string
  AConnection["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Suppress the login dialog box
  AConnection["LoginPrompt"] = 0;
  AConnection["Open"]();
  // Execute a simple query
  RecSet = AConnection["Execute_"]("SELECT * FROM Authors WHERE [Year Born] <> 0");
  // Iterate through query results and insert data into the test log
  RecSet["MoveFirst"]();
  while (!RecSet["EOF"])
  {
    Log["Message"](RecSet["Fields"]("Author")["Value"], RecSet["Fields"]("Year Born")["Value"]);
    RecSet["MoveNext"]();
  };
  AConnection["Close"]();
}

See Also

ADO.CreateCommand

Highlight search results