PRB: Error: "Invalid cursor name" & "No cursor name available"

Last reviewed: July 31, 1997
Article ID: Q120511
1.50 1.51 WINDOWS kbprg kbprb

The information in this article applies to:

   The Microsoft Foundation Classes (MFC), included with:
    - Microsoft Visual C++ for Windows, versions 1.5 and 1.51

SYMPTOMS

A program using the Microsoft Foundation Class Library Database Classes may receive one of the following ODBC error messages when trying to update a record following a call to CRecordset::Requery():

   Invalid cursor name
   State:34000,Native:0,Origin:[Microsoft][ODBC Cursor Library]

      -or-

   No cursor name available
   State:S1015,Native:0,Origin:[Microsoft][ODBC SQL Server Driver]

The following code produces the the S1015 ODBC error:

    CMyRecordSet set;
    set.m_strFilter = "CustNo = ?";
    set.m_CustNoParam = 1;
    set.Open();

    set.m_CustNoParam = 1;
    set.Requery();

    set.Edit();
    set.m_CustNo = 2;

    set.Update();

Note: The ODBC drivers that shipped with VC++ 1.52 are ODBC 2.0 compliant and should not exhibit this behavior. No Microsoft 32-bit driver should exhibit this behavior.

CAUSE

The MFC database classes do not explicitly set a cursor name with the SQLSetCursorName call. Thus the MFC database classes depend on implicit cursor names given by the ODBC driver by default. The 1.0 ODBC Specification did not specify that an implicit cursor remain with the statement handle until the hstmt was dropped. Hence, the implicit cursor name in the SQL Server driver goes away just before the recordset.Update() call in the above example, resulting in the "No Cursor Name available" message when the MFC Database classes call SQLGetCursorName (Line 2421 in the UpdateInsertDelete method in dbcore.cpp).

You can receive the "Invalid cursor name" message under similar circumstances especially after you have traversed a recordset and before requerying.

RESOLUTION

The version 2.0 "ODBC Specification" requires that implicit cursor names must remain until statement handles have been dropped. The drivers provided with the ODBC Driver pack, version 2.0, have been changed to conform to the 2.0 specification. These drivers may be used with the MFC library database classes without running into the above problem.

STATUS

For more information on version 2.0 of the ODBC Driver pack, please see the file ODBCDD20.DOC (in Microsoft Word format) or the file ODBCDD20.WRI (in Microsoft Write format), which are available via ftp.microsoft.com, under the directory /BUSSYS/SQL_ODBC/ODBC-MRKTG. Information can also be obtained by calling the Microsoft Sales Information Center at (800) 426-9400.

In addition, the text of ODBCDD20 is also available in the following Microsoft Knowledge Base article:

   ARTICLE-ID: Q125235
   TITLE     : INF: ODBC Driver Pack 2.0 Fulfillment Kit Q&A


Additional reference words: 1.50 1.51 2.51
KBCategory: kbprg
KBSubcategory: MfcDatabase
Keywords : MfcDatabase kbprg
Technology : kbMfc
Version : 1.50 1.51
Platform : WINDOWS


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