Persistent and Temporary Database Components
Go Up to Connecting to Databases
Each database connection in an application is encapsulated by a database component whether you explicitly provide a database component at design time or create it dynamically at runtime. When an application attempts to connect to a database, it either uses an explicitly instantiated, or persistent
, database component, or it generates a temporary database component that exists only for the lifetime of the connection.
Temporary database components are created as necessary for any datasets in a data module or form for which you do not create yourself. Temporary database components provide broad support for many typical desktop database applications without requiring you to handle the details of the database connection. For most client/server applications, however, you should create your own database components instead of relying on temporary ones. You gain greater control over your databases, including the ability to
- Create persistent database connections
- Customize database server logins
- Control transactions and specify transaction isolation levels
- Create event notifiers to track when a connection is made or broken
Using Temporary Database Components
Temporary database components are automatically generated as needed. For example, if you place a TIBTable
component on a form, set its properties, and open the table without first placing and setting up a TIBDatabase
component and associating the table component with it, Delphi creates a temporary database component for you behind the scenes.
The default properties created for temporary database components provide reasonable, general behaviors meant to cover a wide variety of situations. For complex, mission-critical client/server applications with many users and different requirements for database connections, however, you should create your own database components to tune each database connection to your application’s needs.
Creating Database Components at Design Time
The InterBase page of the Tool Palette contains a database component you can place in a data module or form. The main advantages to creating a database component at design time are that you can set its initial properties and write OnLogin
events for it. OnLogin
offers you a chance to customize the handling of security on a database server when a database component first connects to the server. For more information about managing connection properties, see Connecting to a Database Server. For more information about server security, see Controlling Server Login.