Iterating Through a Session's Database Components
Go Up to Managing database sessions Index
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:
var MaxDbCount: Integer; begin with Session do if (DatabaseCount > 0) then for MaxDbCount := 0 to (DatabaseCount - 1) do Databases[MaxDbCount].KeepConnection := True; end;
if (Session->DatabaseCount > 0) for (int MaxDbCount = 0; MaxDbCount < Session->DatabaseCount; MaxDbCount++) Session->Databases[MaxDbCount]->KeepConnection = true;