Iterating Through a Session's Database Components

From RAD Studio
Jump to: navigation, search

Go Up to Managing database sessions Index

Note: The Borland Database Engine (BDE) has been deprecated, so it will not be enhanced. For instance, BDE will never have Unicode support. You should not undertake new development with BDE. Consider migrating your existing database applications from BDE to dbExpress.

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 run time, 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:

  MaxDbCount: Integer;
  with Session do
    if (DatabaseCount > 0) then
      for MaxDbCount := 0 to (DatabaseCount - 1) do
        Databases[MaxDbCount].KeepConnection := True;
if (Session->DatabaseCount > 0)
  for (int MaxDbCount = 0; MaxDbCount < Session->DatabaseCount; MaxDbCount++)
    Session->Databases[MaxDbCount]->KeepConnection = true;

See Also