CdbError Object

See Also      Properties

A CdbError object contains details about data access errors, each of which pertains to a single operation involving DAO.



Remarks

Any operation involving DAO can generate one or more errors. For example, a call to an ODBC server might result in a database server error, an ODBC error, and a DAO error. As each error occurs, a CdbError object is placed in the Errors collection of the CdbDBEngine object. A single event can, therefore, result in several CdbError objects appearing in the Errors collection.

When a subsequent DAO operation generates an error, the Errors collection is cleared and one or more new CdbError objects are placed in the Errors collection. DAO operations that don't generate an error have no effect on the Errors collection.

The set of CdbError objects in the Errors collection describes one error. The first CdbError object is the lowest level error (the originating error), the second is the next higher level error, and so forth. For example, if an ODBC error occurs while trying to open a CdbRecordset object, the first CdbError object — Errors(0) — contains the lowest level ODBC error; subsequent errors contain the ODBC errors returned by the various layers of ODBC. In this case, the ODBC driver manager, and possibly the driver itself, return separate CdbError objects. The last CdbError object — Errors.Count-1 — contains the DAO error indicating that the object couldn't be opened.

Enumerating the specific errors in the Errors collection enables your error-handling routines to more precisely determine the cause and origin of an error, and take appropriate steps to recover. On both Microsoft Jet and ODBCDirect workspaces, you can read the CdbError object’s properties to obtain specific details about each error, including:

CdbError Constructor Syntax

Use any one of the following three constructors. The qualifier 'CONSTRUCTOR' in the syntax models is provided to help readability. It has no syntactic value.

CONSTRUCTORCdbError(VOID);

This constructor creates an instance of the class. There are no parameters.

CONSTRUCTORCdbError(const CdbError &);

Type Description
const CdbError & Reference to an object.

This constructor creates a copy of the object referenced in the parameter.

CONSTRUCTORCdbError(DAOError *perr,

BOOL bAddRef = FALSE);

Type Argument Description
DAOError * perr A DAO Automation interface pointer corresponding to this DAO class.
BOOL bAddRef
=FALSE
Optional. A Boolean. If TRUE, the DAO Automation interface AddRef function is called.

DAO functionality is presented through pointers to DAO Automation interfaces. This constructor makes a DAO interface available in the form of a DAO class object that provides additional functionality.

This constructor is not required for typical use. It is provided to enable you to easily create a DAO class object if you have access to the corresponding DAO interface.

When the destructor for the DAO object is invoked, the underlying Automation interface's Release member is called. If Release decrements the interface's reference count to zero, the pointer to the Automation interface can be deleted. If you don't want this to happen (for example, because you want to discard the DAO object, but continue using the Automation interface), specify TRUE for the second parameter. The underlying Automation interface's AddRef member is called, which counterbalances the eventual call to Release.