FIX: Assertion Occurs When Calling BeginTrans()ID: Q112756
|
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:
The message is displayed in a message box. When running under the debugger, the message is also displayed in the Output window.File dbcore.cpp, Line 549, Assertion Failed!
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.
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.
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 : kbDatabase kbMFC kbODBC kbVC
Version : 1.50
Platform : WINDOWS
Issue type :
Last Reviewed: July 29, 1999