PRB: Incorrect Syntax Near 'FOR' When Calling Stored Procedure

Last reviewed: July 18, 1997
Article ID: Q164678
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++ for Windows, 16-bit edition, version 1.52

SYMPTOMS

Opening a snapshot-type recordset and calling a SQL Server stored procedure in Open() throws a CDBException with the following error message:

      DBMS: Microsoft SQL Server, Version: 06.00.0121
      Incorrect syntax near the keyword 'FOR'.
      State:37000[Microsoft][ODBC SQL Server Driver][SQL Server]

CAUSE

When you open a snapshot with the default settings, the 16-bit MFC ODBC classes add a "FOR UPDATE OF" clause at the end of the SQL statement. The SQL Server ODBC drivers (2.10.2401 or later) do not accept this clause with the CALL statement.

RESOLUTION

Open the recordset as readOnly when you use a CALL statement to execute a stored procedure.

     MyCRecordset rs;
     rs.Open(CRecordset::snapshot,"{CALL sp_myproc}";
     CRecordset::readOnly);

MORE INFORMATION

This behavior is by design.

The Microsoft SQL Server ODBC driver version 2.00.1912 that ships with Visual C++ 1.52, accepts the ‘FOR UPDATE OF’ clause. However, newer SQL Server ODBC drivers (version 2.10.2401 or later) will return an error in SQLPrepare() when you call a stored procedure in a snapshot-type recordset with default options.

The exception is thrown when SQLPrepare() is executed at line 1226 in dbcore.cpp.

The 32-bit MFC ODBC classes do not add the "FOR UPDATE OF" clause to a CALL statement.

REFERENCES

The Non-supported ODBC SQL Grammar section in drvssrvr.hlp (SQL Server driver help file)

For more information, please see the following article in the Microsoft Knowledge Base:

      ARTICLE-ID: Q131401
      TITLE     : PRB: Couldn't Find Object on Recordset for Predefined
                  Query
 

	
	


Keywords : kb16bitonly MfcDatabase kbprb
Technology : kbMfc
Version : 1.52 2.52
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 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.