FIX: AppendOnly Snapshot Recordset Update() Causes Error (140598)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 2.2
This article was previously published under Q140598 SYMPTOMS
Opening a recordset as an append-only snapshot with no cursor library
support leads to an internal application error (ICE) when Update() is
called to commit an AddNew(). A CDBException is thrown and the following
error is displayed in the output window of the debugger (DB tracing
enabled):
In Visual C++ 2.x using the Microsoft Access 7.0 driver:
Error: failure updating record.
Invalid argument value
State:S1009,Native:57,Origin:[Microsoft][ODBC Microsoft Access
7.0 Driver]
This happens when the cursor library is inhibited from loading by passing
FALSE as the last parameter to CDatabase Open() prior to opening the
recordset or if the cursor library fails to load for any reason.
CAUSE
A snapshot recordset relies on the cursor library for additions or updates
to the database. If the cursor library is not loaded, the recordset becomes
read-only and does not allow additions or updates. In this case, the
recordset member variable m_bUpdatable is correctly set to FALSE, but due
to a bug in MFC, if the recordset is opened appendOnly, m_bAppendable is
still set to TRUE. AddNew() checks m_bAppendable and continues to process
the addition. Eventually, Update() is called. Because the cursor library is
not present, Update() calls CRecordset::ExecuteSetPosUpdate() to use
SQLSetPos for performing the update. SQLSetPos fails and generates the
error message.
If the appendOnly option is not specified for the snapshot, then both
m_bUpdatable and m_bAppendable are set properly and the expected behavior
occurs: - This error message is displayed in the output window when AddNew()
is called: "Recordset is read-only."
- A CDBException is thrown.
RESOLUTION
Snapshots become read-only if the cursor library is not loaded. To get an
updatable and appendable snapshot, make sure the cursor library is properly
loaded by the application.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This problem was corrected in Visual C++
version 4.0.
Modification Type: | Major | Last Reviewed: | 10/24/2003 |
---|
Keywords: | kbbug kbDatabase kbfix KB140598 |
---|
|