Click here to Skip to main content
15,901,122 members
Home / Discussions / Database
   

Database

 
AnswerRe: The Best Free Database for real-time data storing and querying Pin
Eddy Vluggen26-Jan-21 12:36
professionalEddy Vluggen26-Jan-21 12:36 
QuestionDatabase ADO exception on adding new record Pin
Peter Mortier16-Oct-20 4:21
Peter Mortier16-Oct-20 4:21 
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 :

C++
#include <Windows.h>
#include <iostream>
#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 _hr = raw_Close();
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _hr;
}

Exception number is 0x800a0c93

This happens after a couple of hundreds of thousends writes.


Am I missing something?
Any help is appreciated very much!
GeneralRe: Database ADO exception on adding new record Pin
Richard MacCutchan16-Oct-20 4:53
mveRichard MacCutchan16-Oct-20 4:53 
AnswerRe: Database ADO exception on adding new record Pin
CHill6016-Oct-20 5:18
mveCHill6016-Oct-20 5:18 
GeneralRe: Database ADO exception on adding new record Pin
Peter Mortier19-Oct-20 1:58
Peter Mortier19-Oct-20 1:58 
AnswerRe: Database ADO exception on adding new record Pin
Peter Mortier19-Oct-20 2:00
Peter Mortier19-Oct-20 2:00 
GeneralRe: Database ADO exception on adding new record Pin
Victor Nijegorodov19-Oct-20 7:07
Victor Nijegorodov19-Oct-20 7:07 
GeneralRe: Database ADO exception on adding new record Pin
Peter Mortier20-Oct-20 8:40
Peter Mortier20-Oct-20 8:40 
GeneralRe: Database ADO exception on adding new record Pin
Victor Nijegorodov20-Oct-20 9:29
Victor Nijegorodov20-Oct-20 9:29 
QuestionDatabase design and custom query for this use case ? Pin
karengsh13-Oct-20 23:17
karengsh13-Oct-20 23:17 
QuestionShould I store files in a database? Pin
Member 1260015012-Oct-20 22:37
Member 1260015012-Oct-20 22:37 
AnswerRe: Should I store files in a database? Pin
Richard Deeming12-Oct-20 22:54
mveRichard Deeming12-Oct-20 22:54 
QuestionMYSQL Pin
Member 147129666-Oct-20 10:21
Member 147129666-Oct-20 10:21 
AnswerRe: MYSQL Pin
ZurdoDev6-Oct-20 10:34
professionalZurdoDev6-Oct-20 10:34 
QuestionDatabase scripts version control process/strategy? Pin
Member 1363071429-Sep-20 6:06
Member 1363071429-Sep-20 6:06 
AnswerRe: Database scripts version control process/strategy? Pin
David Mujica29-Sep-20 7:48
David Mujica29-Sep-20 7:48 
AnswerRe: Database scripts version control process/strategy? Pin
ZurdoDev29-Sep-20 9:05
professionalZurdoDev29-Sep-20 9:05 
QuestionSimple Database design Pin
fdanos23-Sep-20 20:23
professionalfdanos23-Sep-20 20:23 
AnswerRe: Simple Database design Pin
Victor Nijegorodov23-Sep-20 20:54
Victor Nijegorodov23-Sep-20 20:54 
AnswerRe: Simple Database design Pin
Mycroft Holmes24-Sep-20 12:18
professionalMycroft Holmes24-Sep-20 12:18 
QuestionWhy does MySQL not convert dates before 2010-01-01? Pin
fd97507-Sep-20 2:35
professionalfd97507-Sep-20 2:35 
AnswerRe: Why does MySQL not convert dates before 2010-01-01? Pin
Jörgen Andersson7-Sep-20 4:18
professionalJörgen Andersson7-Sep-20 4:18 
GeneralRe: Why does MySQL not convert dates before 2010-01-01? Pin
fd97507-Sep-20 21:14
professionalfd97507-Sep-20 21:14 
AnswerRe: Why does MySQL not convert dates before 2010-01-01? Pin
ZurdoDev21-Sep-20 7:03
professionalZurdoDev21-Sep-20 7:03 
QuestionHow to use a FileInfo control to add a filename to an Access database Pin
rodgerm25-Aug-20 14:51
rodgerm25-Aug-20 14:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.