Microsoft KB Archive/156930

{|
 * width="100%"|

FIX: "Invalid Cursor State" Error After Changing Directory

 * }

-

The information in this article applies to:


 * Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0
 * ActiveX Data Objects (ADO), version 1.5

-

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.

This has been fixed in the latest components of MDAC (MDAC 1.5c and above). Now, the Cursor library is creating the temporary files in the TEMP directory.

Additional query words:

Keywords : kbprg kbADO150fix kbDatabase kbMFC kbODBC kbVC kbVC210bug kbVC410bug kbVC420bug kbVC500bug kbGrpVCDB kbGrpMDAC

Version : WINDOWS:1.5; winnt:2.0,2.1,2.2,4.0,4.1,4.2,5.0

Platform : WINDOWS winnt

Issue type : kbbug

Technology : kbvcSearch