PRB: C2664 Error When Using CNoAccessor (190981)



The information in this article applies to:

  • Microsoft OLE DB, when used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q190981

SYMPTOMS

Using the CNoAccessor class as a template argument for CCommand or CTable causes the following error:
   atldbcli.h(2819) : error C2664: 'SetAccessor' : cannot convert
     parameter 1 from 'class ATL::CAccessorRowset<class
     ATL::CNoAccessor,class ATL::CRowset> *const ' to 'class
     ATL::CAccessorBase *'
   Types pointed to are unrelated; conversion requires reinterpret_cast,
   C-style cast or function-style cast
					
For example, the following code causes the error to occur:
   CCommand<CNoAccessor> cmd;
				

CAUSE

The second argument of the CCommand<> or CTable<> template is the rowset class. By default, this is set to CRowset. The CRowset class assumes that there will be an accessor used. Therefore, it is necessary to specify CNoRowset or some other user-defined rowset class that doesn't rely on an accessor.

RESOLUTION

To use CNoAccessor, specify "CNoRowset" for the rowset class argument of the CCommand or CTable template classes.

The code resembles the following:
   CCommand<CNoAccessor, CNoRowset>
				
If, for some reason, you need to specify CNoAccessor but still want some of the functionality of the CRowset class, derive a new class from CRowset and override any functions that rely on an accessor.

STATUS

This behavior is by design.

MORE INFORMATION

Below is an example of how you might use the CNoAccessor class:
   #include <atlbase.h>
   #include <atldbcli.h>

   int main(int argc, char* argv[])
   {
   HRESULT hr;
      CoInitialize(NULL);

      CDataSource ds;
      CSession sn;
      hr = ds.OpenFromInitializationString(
                     L"Provider=MSDASQL;Data Source=YourDSN");
      hr = sn.Open(ds);

           CCommand<CNoAccessor, CNoRowset> cmd;
      CDBPropSet ps(DBPROPSET_ROWSET);
      ps.AddProperty(DBPROP_IRowsetChange, true);
      ps.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_DELETE);
      hr = cmd.Open(sn, "INSERT INTO Table1 VALUES('Col1Value',
                         'Col2Value')", &ps , NULL, DBGUID_DBSQL, false);
           // No returned results so need to bind anything
      cmd.Close();

      return 0;
   }
				

Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbConsumer kbDatabase kbDTL kbMDACNoSweep kbprb kbtemplate KB190981 kbAudDeveloper