PRB: "Invalid Cursor State" Error After Changing Directory

Last reviewed: July 3, 1997
Article ID: Q156930
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0

SYMPTOMS

When using a snapshot recordset with the cursor library loaded passing TRUE for the last argument of CDatabase::Open() or using the CDatabase::useCursorLib flag in the OpenEx() call), you may receive the following ODBC error when trying to do any operation on the recordset following a directory change:

   State:24000
   Invalid Cursor State

CAUSE

The cursor library creates a temporary file that is used for caching results of the recordset. This temporary file, which starts with CTT..., is created in the current working directory. If the current working directory is changed while a recordset is open, the "Invalid Cursor State" error can occur.

RESOLUTION

Do not change working directories while a recordset is open or do not use the cursor library. If you must change the current working directory, save and restore it before performing the next CRecordset operation. Do this by using the GetCurrentDirectory() and SetCurrentDirectory() Windows API functions.

CFileDialog will change the working directory. If you do not want CFileDialog to change the working directory after you close it, you can use the OFN_NOCHANGEDIR flag. For example:

   CFileDialog dlgFile;
   dlgFile.m_ofn.Flags|=OFN_NOCHANGEDIR;
   dlgFile.DoModal();

STATUS

This behavior is by design.


Keywords : kbprg MfcDatabase
Technology : kbMfc
Version : 2.0 2.1 2.2 4.0 4.1 4.2 5.0
Platform : NT WINDOWS
Issue type : kbprb


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: July 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.