Why am I still connected to my database after my RWDBConnections have gone out of scope?

Article ID: 865
Last updated: 05 Feb, 2008
Article ID: 865
Last updated: 05 Feb, 2008
Revision: 1
Views: 2911
Posted: 08 Oct, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


The RWDBConnections I've created have all gone out of scope, but my program is still connected to my database. Why?


Cause


When a RWDBDatabase instance is created, it creates a Connection Pool and establishes a default connection (to the database) inside the Connection Pool. Now when you create a new RWDBConnection object for the first time, it just references to the default connection and doesn't create new connection. The second connection object creates a new connection to the database. This Connection pool keeps a set number of connections open, even after an RWDBConnection gets destructed, to reduce the cost of creating a new RWDBConnection. The default for this number is one.


Action


If you would like to turn off this connection pooling behavior on your RWDBDatabase, you can do so by calling the RWDBDatabase::defaultConnections() method but at the same time, you have to avoid getting a connection during the creation of the RWDBDatabase object by calling RWDBDatabase::connect(FALSE)
main()
{
//please go through the documentation on the method below
RWDBDatabase::connect(FALSE);

// initialize the database
RWDBDatabase aDB = ...;

// turn off connection pooling by setting size to 0
aDB.defaultConnections(0);

Note that setting the size lower doesn't automatically destroy existing connections, but simply allows them to be destroyed when your RWDBConnection goes out of scope. Also, for reasons above, making this change may change the amount of time required to create a new connection.

See your DBTools.h++ Class Reference for details.


This article was:   Helpful | Not helpful
Report an issue
Article ID: 865
Last updated: 05 Feb, 2008
Revision: 1
Views: 2911
Posted: 08 Oct, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category