Closing Database Connections
Go Up to Managing database sessions Index
To close an individual database connection, call the CloseDatabase method. When you call CloseDatabase, the reference count for the database, which is incremented when you call OpenDatabase, is decremented by 1. When the reference count for a database is 0, the database is closed. CloseDatabase takes one parameter, the database to close. If you opened the database using the OpenDatabase method, this parameter can be set to the return value of OpenDatabase.
If the specified database name is associated with a temporary (implicit) database component, and the session's KeepConnections property is False, the database component is freed, effectively closing the connection.
There are two ways to close all database connections within the session:
- Set the Active property for the session to False.
- Call the Close method for the session.
When you set Active to False, Delphi automatically calls the Close method. Close disconnects from all active databases by freeing temporary database components and calling each persistent database component's Close method. Finally, Close sets the session's BDE handle to nil.