Microsoft KB Archive/155848

= PRB: ODBC Error When Using CRecordset Without Deriving From It =

Article ID: 155848

Article Last Modified on 11/21/2006

-

APPLIES TO

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

 Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

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

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

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

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

-

<div class="notice_section">

This article was previously published under Q155848

<div class="symptoms_section">

SYMPTOMS
With Visual C++ 4.2 and later, you can use the CRecordset class without deriving from it, allowing you to open a read-only recordset on any data source. This may be helpful if you are using CRecordset::GetFieldValue, for example. However, when calling Open for the CRecordset object, you may see a message box with the following message in it:

No columns were bound prior to calling SQLExtendedFetch

<div class="cause_section">

CAUSE
The CDatabase object used by the CRecordset object loaded the ODBC cursor library. The cursor library requires that there be at least one bound column for a recordset. The Visual C++ documentation doesn't make this requirement clear.

<div class="resolution_section">

RESOLUTION
Do not load the cursor library by specifying FALSE for the last argument of CDatabase::Open. For example: CDatabase db; db.Open("MyDataSource", FALSE, FALSE, "ODBC;", FALSE); CRecordset rs( &db ); rs.Open(...); ... If your driver does not support dynasets, then the cursor library is required and you will not be able to use the CRecordset class without deriving from it.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem with the Visual C++ 4.2 documentation. The Visual C++ 5.0 documentation has been changed to reflect this information and states:

Note if you declare a recordset object without deriving from CRecordset, do not have the ODBC Cursor Library loaded. The cursor library requires that the recordset have at least one bound column; however, when you use CRecordset directly, none of the columns are bound. The member functions CDatabase::OpenEx and CDatabase::Open control whether the cursor library will be loaded."

Keywords: kbdatabase kbdocfix kbmdacnosweep kbprb kbprogramming kbusage KB155848

-

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

© Microsoft Corporation. All rights reserved.