Connection object

To access the data stored in databases, you must first connect to the database. The Connection object connects your Dexterity-based application to an existing database.

Creating a Connection object

Use the new keyword to create a new Connection object.

{Create a new Connection object.}
connection = new ADODB.Connection();

When using Distributed COM (DCOM), create a new Connection object with the COM_CreateObject() function. In the following example, a new Connection object is created on the computer “SystemServer”.

{Create a new Connection object.}
connection = COM_CreateObject("ADODB.Connection", "SystemServer");

Creating a Connection object doesn’t connect your Dexterity-based application to a database. You must also use the Open method or the ActiveConnection property to connect to a specific database.


Opening a connection

Use the Open method to open a connection to a database. You must specify both the database type and the name of an existing database in the connection string.

{Open a connection to a database.}
conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb";
connection.Open(conString);

In the previous example, the name of the database is db.mdb, and the specified database type is a Microsoft Jet database. For more information about specifying database types, refer to the help file for the Microsoft ADO Object Library.

Retrieving a connection

When a Microsoft ADOX Object Library catalog is created, a connection to the database is also created. You can retrieve the connection with the ActiveConnection property from the Catalog object.

{Retrieve a connection from a catalog object.}
connection = catalog.ActiveConnection;

Closing a connection

Use the Close method to close a connection.

{Close a connection.}
connection.Close();

Be sure to close all connections to a database. If you don’t, you may get unpredictable results.



Documentation Feedback