Managing Database Sessions

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.

A BDE-based application's database connections, drivers, cursors, queries, and so on are maintained within the context of one or more BDE sessions. Sessions isolate a set of database access operations, such as database connections, without the need to start another instance of the application.

All BDE-based database applications automatically include a default session component, named Bde.DBTables.Session, which encapsulates the default BDE session. When database components are added to the application, they are automatically associated with the default session (note that its SessionName is "Default"). The default session provides global control over all database components not associated with another session, whether they are implicit (created by the session at run time when you open a dataset that is not associated with a database component you create) or persistent (explicitly created by your application). The default session is not visible in your data module or form at design time, but you can access its properties and methods in your code at run time.

To use the default session, you need to write no code unless your application must:

Whether you add database components to an application at design time or create them dynamically at run time, they are automatically associated with the default session unless you specifically assign them to a different session. If you open a dataset that is not associated with a database component, Delphi automatically:

  • Creates a database component for it at run time.
  • Associates the database component with the default session.
  • Initializes some of the database component's key properties based on the default session's properties. Among the most important of these properties is KeepConnections, which determines when database connections are maintained or dropped by an application.

The default session provides a widely applicable set of defaults that can be used with no changes by most applications. You only need to associate a database component with an explicitly named session if the component performs a simultaneous query against a database already opened by the default session. In this case, each concurrent query must run under its own session. Multithreaded database applications also require multiple sessions, where each thread has its own session.

Applications can create additional session components as needed. BDE-based database applications automatically include a session list component, named Bde.DBTables.Sessions, which you can use to manage all of your session components. For more information about managing multiple sessions, see Managing Multiple Sessions.

You can safely place session components in data modules. If you put a data module that contains one or more session components into the Object Repository, however, make sure to set the AutoSessionName property to True to avoid namespace conflicts when users inherit from it.

See Also