RAD Studio |  |

Opening Database Connections
See Also
Collapse All

To open a database connection within a session, call the OpenDatabase method. OpenDatabase takes one parameter, the name of the database to open. This name is a BDE alias or the name of a database component. For Paradox or dBASE, the name can also be a fully qualified path name. For example, the following statement uses the default session and attempts to open a database connection for the database pointed to by the DBDEMOS alias:

Copy Code

    var
      DBDemosDatabase: TDatabase;
    begin
      DBDemosDatabase := Session.OpenDatabase('DBDEMOS');
      ...

Copy Code

    TDatabase *BCDemosDatabase = Session->OpenDatabase("BCDEMOS");

OpenDatabase actives the session if it is not already active, and then checks if the specified database name matches the DatabaseName property of any database components for the session. If the name does not match an existing database component, OpenDatabase creates a temporary database component using the specified name. Finally, OpenDatabase calls the Open method of the database component to connect to the server. Each call to OpenDatabase increments a reference count for the database by 1. As long as this reference count remains greater than 0, the database is open.

See Also

Closing Database Connections

Dropping Temporary Database Connections

Iterating Through a Session's Database Components

Searching for a Database Connection

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!