PRB: Couldn't Find Object on Recordset for Predefined Query

ID: Q131401

1.50 1.51 1.52 1.52a WINDOWS kbusage kbprb

The information in this article applies to:

SYMPTOMS

When using the MFC database classes and trying to open a snapshot recordset for a Microsoft Access version 2.0 predefined query, a database exception is thrown, and the following error message is seen in the output window:

   Couldn't find object '|'.
   State:S0002[Microsoft][ODBC Microsoft Access 2.0 Driver]

CAUSE

The MFC encylopedia article "Recordset: Declaring a Class for a Predefined Query" discusses how to make a CRecordset class that opens a predefined query. It mentions that the database classes don't support updating predefined queries. It doesn't explicitly mention that you have to open your recordset as read-only, but you should.

If a recordset is opened as a snapshot without specifying a read-only recordset, the database classes append the string "FOR UPDATE OF" to the end of the SQL statement that defines a query. This added phrase is invalid in a SQL statement that uses the CALL keyword to execute a predefined query.

RESOLUTION

To avoid this problem, open the recordset as read-only by specifying CRecordset::readOnly as the third parameter to the CRecordset::Open() function. Your open function should look something like this:

   myRecordset.Open(CRecordset::snapshot,     // open as snapshot
                    "{call MyQuery}",         // call predefined query
                    CRecordset::readOnly);    // must be read-only!

STATUS

This behavior is by design.

REFERENCES

MFC Encyclopedia Article, "Recordset: Declaring a Class for a Predefined Query.

Additional reference words: 2.50 2.51 2.52 2.52a KBCategory: kbusage kbprb KBSubcategory: MfcDatabase

Keywords          : kberrmsg kb16bitonly kbDatabase kbMFC kbODBC kbVC 
Version           : 1.50 1.51 1.52 1.52a
Platform          : WINDOWS

Last Reviewed: May 22, 1998