FIX: Assertion Occurs When Calling BeginTrans()

Last reviewed: September 18, 1997
Article ID: Q112756
1.50 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

   The Microsoft Foundation Classes (MFC), included with:
    - Microsoft Visual C++ for Windows, 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 that "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 reference words: 1.50 2.50 Transaction
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcDatabase

Keywords : MfcDatabase kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 1.50
Platform : WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.