Associating a Dataset with Database and Session Connections

From RAD Studio
Jump to: navigation, search

Go Up to Using BDE-enabled datasets 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.

In order for a BDE-enabled dataset to fetch data from a database server, it needs to use both a database and a session.

Databases represent connections to specific database servers. The database identifies a BDE driver, a particular database server that uses that driver, and a set of connection parameters for connecting to that database server. Each database is represented by a Bde.DBTables.TDatabase component. You can either associate your datasets with a TDatabase component you add to a form or data module, or you can simply identify the database server by name and let Delphi generate an implicit database component for you. Using an explicitly created TDatabase component is recommended for most applications, because the database component gives you greater control over how the connection is established, including the login process, and lets you create and use transactions.

To associate a BDE-enabled dataset with a database, use the DatabaseName property. DatabaseName is a string that contains different information, depending on whether you are using an explicit database component and, if not, the type of database you are using:

  • If you are using an explicit TDatabase component, DatabaseName is the value of the DatabaseName property of the database component.
  • If you want to use an implicit database component and the database has a BDE alias, you can specify a BDE alias as the value of DatabaseName. A BDE alias represents a database plus configuration information for that database. The configuration information associated with an alias differs by database type (Oracle, Sybase, InterBase, Paradox, dBASE, and so on).
  • If you want to use an implicit database component for a Paradox or dBASE database, you can also use DatabaseName to simply specify the directory where the database tables are located.

A session provides global management for a group of database connections in an application. When you add BDE-enabled datasets to your application, your application automatically contains a session component, named Bde.DBTables.Session. As you add database and dataset components to the application, they are automatically associated with this default session. It also controls access to password protected Paradox files, and it specifies directory locations for sharing Paradox files over a network. You can control database connections and access to Paradox files using the properties, events, and methods of the session.

You can use the default session to control all database connections in your application. Alternatively, you can add additional session components at design time or create them dynamically at run time to control a subset of database connections in an application. To associate your dataset with an explicitly created session component, use the SessionName property. If you do not use explicit session components in your application, you do not have to provide a value for this property. Whether you use the default session or explicitly specify a session using the SessionName property, you can access the session associated with a dataset by reading the DBSession property.

Note: If you use a session component, the SessionName property of a dataset must match the SessionName property for the database component with which the dataset is associated.

See Also