KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q152318: FIX: DAO SDK’s CdbRecordset::Requery() May Fail

Article: Q152318
Product(s): Microsoft C Compiler
Version(s): 4.0 4.1
Operating System(s): 
Keyword(s): kbProgramming
Last Modified: 04-AUG-2001

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

- The DAO SDK, included with:
   - Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1 
-------------------------------------------------------------------------------

SYMPTOMS
========

Attempting to invoke the DAO SDK's CdbRecordset::Requery() method of the
CdbRecordset class when the recordset has been opened with dbOpenDynaset and
dbDenyWrite, may result in an error message similar to the following:

  

  Unhandled exception in <YourApp>.exe (DAO3032.DLL):
  0xC0000005: Access Violation

CAUSE
=====

Within the implementation of CdbRecordset::Requery found in DBDAO.CPP (line
1645), the casting of a COleVariant method is performed incorrectly. The cast is
performed as:

     Var.pdispVal    = (LPDISPATCH)pq();

The correct implementation should be:

     Var.pdispVal    = (LPDISPATCH)pq->GetInterface();

RESOLUTION
==========

Derive a new class from CdbRecordset and override the Requery method with the
following:

     VOID CdbRecordset::Requery( CdbQueryDef *pq )   // = NULL
     {
         DAORecordset*   prs = (DAORecordset *)GetInterface();
         COleVariant     Var;

         //Manually load the Query Def as a dispatch
         if (!pq)
         {
             Var.vt          = VT_ERROR;
             Var.scode       = DISP_E_PARAMNOTFOUND;
         }
         else
         {
             Var.vt          = VT_DISPATCH;
             Var.pdispVal    = (LPDISPATCH)pq->GetInterface();
         }

         DAOMFC_CALL(prs->Requery(Var));
     }

STATUS
======

Microsoft has confirmed this to be a bug in the Microsoft products listed at the
beginning of this article. This bug was corrected in fixed in the DAO SDK that
comes with Visual C++ version 5.0.

Additional query words:

======================================================================
Keywords          : kbProgramming 
Technology        : kbAudDeveloper kbDAOsearch kbSDKDAOSearch kbSDKSearch
Version           : 4.0 4.1
Issue type        : kbbug
Solution Type     : kbfix

=============================================================================

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.

Copyright Microsoft Corporation 1986-2002.