Microsoft KB Archive/170823

= PRB: CDBException Thrown Opening Recordset on Stored Procedure =

Article ID: 170823

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 2.0 Professional Edition

 Microsoft Visual C++ 2.1

 Microsoft Visual C++ 2.2

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 1.52 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q170823

<div class="symptoms_section">

SYMPTOMS
When you use the "Call" syntax to invoke a stored procedure when opening a recordset, an exception might be thrown. Depending upon the version of Visual C++, whether or not you have DB Tracing enabled and the DBMS in use, you might see one of the following errors:

<pre class="fixed_text">Version:       4.X Message Box:    <See below for DBMS specific error message> Output Window: <See below for DBMS specific error message> State:37000,Native:<DBMS specific>,Origin:[ ] [<driver name/version>][<DBMS--optional>] Error: ODBC failure on SQLPrepare->

<pre class="fixed_text">Version:       2.X Message Box:    Internal application error. Output Window: <See below for DBMS specific error message> State:37000,Native:<DBMS specific>,Origin:[ ] [<driver name/version>][<DBMS--optional>] Error: ODBC failure on SQLPrepare.

<pre class="fixed_text">Version:       1.5X Message Box:   Internal application error. Output Window: <See below for DBMS specific error message> State:37000[ ][<driver name/version>] [<DBMS--optional>]

<pre class="fixed_text">DBMS specific error information:

DBMS                Error String                   Native Code -- SQL Server: Incorrect syntax near the keyword 'EXEC'. 156

Access:     Syntax error in FROM clause. -3506 (and other desktop drivers) NOTE: If you are using Visual C++ 1.5X and connecting to a 16-bit SQL Server datasource, an exception may not be thrown but the desired result set is not returned.

<div class="cause_section">

CAUSE
While this line of code may appear to be a perfectly valid way to invoke a stored procedure, there is a small error:

m_pSet->Open(CRecordset::snapshot, "{ Call szCallTest}");

The space between the "{" and the "C" cause MFC to misinterpret the Call statement as the name of a table. MFC makes a case insensitive comparison between any SQL provided in the Open call and the literal constant szCall, which is defined as _T("{call "). If the comparison fails, the provided SQL is incorrectly incorporated into a SELECT statement that is executed instead of the stored procedure call.

<div class="resolution_section">

RESOLUTION
Make sure that there are no extra spaces between the first curly brace and the "Call" key word.

<div class="status_section">

STATUS
This behavior is by design.

Keywords: kbdatabase kbprb KB170823

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.