RAD Studio |  |

Iterating Through a Session's Database Components
See Also
Collapse All

You can use two session component properties, Databases and DatabaseCount, to cycle through all the active database components associated with a session.

Databases is an array of all currently active database components associated with a session. DatabaseCount is the number of databases in that array. As connections are opened or closed during a session's life-span, the values of Databases and DatabaseCount change. For example, if a session's KeepConnections property is False and all database components are created as needed at runtime, each time a unique database is opened, DatabaseCount increases by one. Each time a unique database is closed, DatabaseCount decreases by one. If DatabaseCount is zero, there are no currently active database components for the session.

The following example code sets the KeepConnection property of each active database in the default session to True:

Copy Code

    var
      MaxDbCount: Integer;
    begin
      with Session do
        if (DatabaseCount > 0) then
          for MaxDbCount := 0 to (DatabaseCount - 1) do
            Databases[MaxDbCount].KeepConnection := True;
    end;

Copy Code

    if (Session->DatabaseCount > 0)
      for (int MaxDbCount = 0; MaxDbCount < Session->DatabaseCount; MaxDbCount++)
        Session->Databases[MaxDbCount]->KeepConnection = true;

See Also

Opening Database Connections

Closing Database Connections

Searching for a Database Connection

Dropping Inactive Database Connections

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