PRB: "Invalid cursor name" and "No cursor name available"
PSS ID Number: Q120012
Article last modified on 11-04-1994
PSS database name: VISUALC

2.50
WINDOWS

----------------------------------------------------------------------
The information in this article applies to:

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

SYMPTOMS
========
In a program that uses the MFC library database classes, you may get one of
the following ODBC error messages if you try 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]

CAUSE
=====
The MFC library database classes do not explicitly set cursor names through
the SQLSetCursorName call. Therefore, the MFC library database classes
depend on implicit default cursor names given by the ODBC driver. The
version 1.0 "ODBC Specification" did not specify that an implicit cursor
must remain with the statement handle until the hstmt is dropped.
Therefore, the implicit cursor name in the SQL Server driver goes away just
before the "recordset.Update()" call does (as seen in the sample code in
the "MORE INFORMATION" section below), resulting in the "No Cursor Name
available" message when the MFC library database classes call
SQLGetCursorName (line 2421 in the UpdateInsertDelete method in the
DBCORE.CPP file).
You can receive the "Invalid cursor name" message under similar
circumstances, but typically this happens if you have traversed a recordset
before requerying.

RESOLUTION
==========
The version 2.0 "ODBC Specification" requires that implicit cursor names
must remain until statement handles have been dropped. The version 2.0 SQL
Server driver has therefore been fixed to conform to this change. The
version 2.0 SQL Server driver may be used with the MFC library database
classes without running into the above problem.

STATUS
======
The ODBC 2.0 SQL Server driver is currently available on CompuServe in
Library 15 of the MSSQL forum. The file is called SQLSVR.EXE. Because the
driver is a beta component, it may be moved and removed, and it may have
its name changed. Contact the SYSOP in section 5 of the MSSQL forum if you
are unable to locate the file.

MORE INFORMATION
================
The following sample code demonstrates how to get the S1015 ODBC error:

Sample Code
-----------

    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();

Additional reference words: 2.50
KBCategory: kbprg
KBSubcategory: MfcDatabase

=============================================================================
Copyright Microsoft Corporation 1994.