Hi, when writing in Access database using ADO and record binding, I run into an exception after some time. I wrote a small console program to demonstrate the problem :
#include #include #import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#include "icrsint.h"
_COM_SMARTPTR_TYPEDEF(IADORecordBinding, __uuidof(IADORecordBinding));
void OpenDatabase();
void WriteToDatabase(int i);
void CloseDatabase();
_ConnectionPtr m_pConnectionPtr = 0;
DWORD64 cnt_recordset;
int main()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
m_pConnectionPtr = NULL;
m_pConnectionPtr.CreateInstance(__uuidof(Connection));
int cnt = 0;
cnt_recordset = 0;
OpenDatabase();
while (1)
{
std::cout << cnt++ << " : " << cnt_recordset << std::endl;
for (int i = 0; i < 1000; i++)
WriteToDatabase(i);
}
CloseDatabase();
CoUninitialize();
}
void OpenDatabase()
{
bstr_t strCnn("Provider=MSDASQL;DSN=TestDB;User ID=sa;");
m_pConnectionPtr->Open(strCnn, "", "", NULL);
}
void CloseDatabase()
{
if ((m_pConnectionPtr->State == adStateOpen))
m_pConnectionPtr->Close();
}
void WriteToDatabase(int i)
{
cnt_recordset++;
class CMyRecordSet : public CADORecordBinding
{
BEGIN_ADO_BINDING(CMyRecordSet)
// Column m\_nID is the 1st field in the table.
ADO\_VARIABLE\_LENGTH\_ENTRY2(1, adInteger, m\_nID, sizeof(m\_nID), m\_IDStatus, FALSE)
// Column m\_bCritical is the 2nd field in the table.
ADO\_FIXED\_LENGTH\_ENTRY(2, adInteger, m\_value, m\_valueStatus, TRUE)
END\_ADO\_BINDING()
public:
int m_nID;
int m_value;
ULONG m_IDStatus;
ULONG m_valueStatus;
};
HRESULT hr = true;
// open recordset
//_RecordsetPtr pRs = NULL;
//pRst.CreateInstance(__uuidof(Recordset));
_RecordsetPtr pRs("ADODB.Recordset");
CMyRecordSet rs;
IADORecordBindingPtr picRs(pRs);
hr = pRs->Open("TTagData",
_variant_t((IDispatch*)m_pConnectionPtr, true),
adOpenKeyset, adLockOptimistic, adCmdTable);
//Bind the Recordset to a C++ Class here.
hr = picRs->BindToRecordset(&rs);
// fill in data
rs.m_value = i;
// add new record to the table
picRs->AddNew(&rs);
// picRs->Release(); tried this but no result
pRs->Close();
}
The exception occurs on closing the recordset after the AddNew :
inline HRESULT Recordset15::Close ( ) {
HRESULT