Share via


DAO: Closing DAO Objects

OverviewHow Do IFAQSampleODBC Driver List

All MFC DAO objects have Close member functions. Calling Close typically closes any subordinate objects, such as the active recordsets in a database object, before closing the parent object. The following illustrates closing a database object:

// pdbAccounts is an open CDaoDatabase object
pdbAccounts->Close( );

****Note   ****It is considered good practice to explicitly close your objects rather than relying on containing objects to close them.

Meaning of the Close Action for Different DAO Objects

The concept of “close” is similar for MFC DAO objects. Closing an object:

  • Releases memory associated with the object, including buffers used to store recordset data.

  • Releases the underlying DAO object.

  • Does not remove the object from any collection it belongs to. The exceptions are the workspace and recordset objects, which don’t persist between database engine sessions.

What Happens When You Close Objects

For details about what happens when you close an MFC DAO object, see the Close member function for that object's class:

 Calling Close does not destroy the MFC object; you must do that separately.

****Tip   ****It is considered good programming practice to explicitly close your objects before they go out of scope.

See Also   , , , , , , , , , , , , ,