Data Access Modes > Data Source Mode > Connection Pooling |
True DataControl set up at design time must use a connection to the database (ADO Connection object) creating its SourceRecordset. If every TData control would create its own separate connection object, that would engender serious performance problems, since establishing a connection is a performance-heavy operation for most databases.
True DataControl uses a pooling technique to minimize the number of simultaneously open connections. When a TData control creates its SourceRecordset, it first checks if a connection with exactly the same properties exists in the pool, was created by another TData control that is still active. If there is such connection, TData uses it instead of creating a new one.
In order for two TData controls to use a single connection, they must be
In DataMode = 0 - DataSource.
Set up at design time. TData controls with SourceRecordset or SourceConnection properties set at run time don't participate in connection pooling.
Active at the same time. They must either belong to the same form, or, if they reside in different forms, the two forms must be shown simultaneously. In other words, pooled connections don't survive their controls. Once a control's form is closed, all its connections are deleted from the pool. Reopening the form will re-create the connections.
The following properties must have exactly the same values (string comparison is case-sensitive):
Example Title |
Copy Code
|
---|---|
ConnectionString, UserName, Password, CursorLocation, Mode, ConnectionTimeout, CommandTimeout |
If you want to pool TData connections in more complex cases, for example, between different forms open at different times, or between different invocations of a form, use the SourceConnection property.
To check the current status of the connection pool, use PooledConnectionCount and PooledConnections properties. These properties allow the developer to examine connections currently in the pool. They are useful when you are in doubt, perhaps not sure if all the connection-related properties have the same values, and want to see what is actually happening. Do not use these two properties for any other purposes than to make sure the connection pool works as intended.
Note: Connection pooling is unavailable in True DataControl Lite. |