I have an Unmanged ATL Dll, which I'm trying to gradually migrate to
managed C++, for easier use from C#-clients.
Internally the ATL-version uses ADO for accessing an Access-database.
This is done by #import'ing msado15.dll and using the smart pointers
(_ConnectionPtr, _RecordsetPtr etc.). As far as I know this should
work just fine in managed code.
The first time I try to call Open on the recordset it returns a
failure-HRESULT: 0x800A0BB9. I gather this means something like:
"Arguments are of the wrong type, are out of acceptable range, or are
in conflict with one another.".
This strikes me as odd, since this code runs just fine in the
ATL-version of the library. Any ideas anyone?
By the way, the connection to the database opens fine. It's only when
I try to open a recordset that I get an error.
Code:
_RecordsetPtr GetAdoRecordset(string sConStr, string sTableName)
{
_bstr_t bstrConStr;
bstrConStr = sConStr.c_str();
_bstr_t bstrTableName;
bstrTableName = sTableName.c_str();
_bstr_t bstrQuery;
bstrQuery = bstrTableName;
_ConnectionPtr pCon;
_RecordsetPtr pRs;
HRESULT hr;
try
{
hr = pCon.CreateInstance(__uuidof(Connection));
pCon->CursorLocation = adUseClient;
hr = pCon->Open(bstrConStr, L"Admin", L"", adOpenUnspecified);
hr = pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation = adUseClient;
pRs->PutRefActiveConnection(pCon.GetInterfacePtr());
// THIS FAILS! RETURNS 0x800A0BB9.
hr = pRs->Open(bstrQuery,vtMissing,adOpenStatic,adLockReadO nly,-1);
pRs->PutRefActiveConnection(NULL);
hr = pCon->Close();
return pRs.Detach();
}
catch(_com_error *e)
{
// errorhandler
}
catch(...)
{
// errorhandler
}
return NULL;
}