## FIX: Assertion Occurs When Calling BeginTrans()

Q112756

The information in this article applies to:

- The Microsoft Foundation Classes (MFC), included with:
  - Microsoft Visual C++, version 1.5

## SYMPTOMS

If CDatabase::BeginTrans() is called a second time for a CDatabase object and the debug version of the Microsoft Foundation Class (MFC) Library is used, the following assertion will occur:

> File dbcore.cpp, Line 549, Assertion Failed!

The message is displayed in a message box. When running under the debugger, the message is also displayed in the Output window.
This problem occurs even though CDatabase::CommitTrans() was called after the first CDatabase::BeginTrans() call.

## CAUSE

The CDatabase class uses a variable called "m_bTransactionPending" for debug mode, which gets set to TRUE in CDatabase::BeginTrans() with the following code:

       #ifdef _DEBUG
           m_bTransactionPending = TRUE;
       #endif // _DEBUG

The m_bTransactionPending variable should be assigned FALSE (but is not) in the CDatabase::CommitTrans() function. Here is the code:

       #ifdef DEBUG
           m_bTransactionPending = FALSE;
       #endif // DEBUG

NOTE: "DEBUG:" was used rather than "_DEBUG". This is a bug that occurs only when using the debug version of the Microsoft Foundation Class Library.

## RESOLUTION

Modify the code in CommitTrans() by changing the DEBUG constant to _DEBUG, and rebuild the MFC library by following the directions in the README.TXT located in the \MSVC\MFC\SRC directory.
As an alternative, you could copy the code from CommitTrans() into a new member function of a CDatabase-derived class, fix the code, and call the new function instead of CommitTrans(). However, if you're letting CRecordset create the database object (that is, not passing a pointer to a CDatabase object into the constructor), CDatabase will be used instead of your CDatabase-derived class.

## STATUS

Microsoft has confirmed this to be a bug in the Microsoft Foundation Class Library version 2.5. This bug was corrected in Visual C++ for Windows, version 1.51 (MFC 2.51).

Additional query words: 1.50 2.50 Transaction

Keywords : kb16bitonly kbDatabase kbMFC kbODBC kbVC
Issue type :
Technology : kbAudDeveloper kbMFC

Last Reviewed: May 8, 2001 © 2001 Microsoft Corporation. All rights reserved. Terms of Use.