Activating a Session

From RAD Studio
Jump to: navigation, search

Go Up to Managing database sessions Index

Attention: 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.

Active is a Boolean property that determines whether database and dataset components associated with a session are open. You can use this property to read the current state of a session database and dataset connections, or to change it. If Active is False (the default), all databases and datasets associated with the session are closed. If True, databases and datasets are open.

A session is activated when it is first created, and subsequently, whenever its Active property is changed to True from False (for example, when a database or dataset associated with a session is opened and there are currently no other open databases or datasets). Setting Active to True triggers a session Bde.DBTables.TSession.OnStartup event, registers the paradox directory locations with the BDE, and registers the ConfigMode property, which determines what BDE aliases are available within the session. You can write an OnStartup event handler to initialize the NetFileDir, PrivateDir, and ConfigMode properties before they are registered with the BDE, or to perform other specific session start-up activities.

Once a session is active, you can open its database connections by calling the OpenDatabase method.

For session components you place in a data module or form, setting Active to False when there are open databases or datasets closes them. At run time, closing databases and datasets may trigger events associated with them.

Note: You cannot set Active to False for the default session at design time. While you can close the default session at run time, it is not recommended.

You can also use a session Open and Close methods to activate or deactivate sessions other than the default session at run time. For example, the following single line of code closes all open databases and datasets for a session:

Delphi:

Session1.Close;

C++:

Session1->Close();

This code sets Session1 Active property to False. When a session Active property is False, any subsequent attempt by the application to open a database or dataset resets Active to True and calls the session OnStartup event handler, if it exists. You can also explicitly code session reactivation at run time. The following code reactivates Session1:

Delphi:

Session1.Open;

C++:

Session1->Open();
Note: If a session is active, you can also open and close individual database connections. For more information, see Closing Database Connections.

See Also