_CtrIsValidHeapPointer(pUserData) problem

I have made a connection to the sql server using ADO within a DLL function. It wokrs fine...

However when I stop my application it prompt an error
File: dbgheap.c
Line: 1011
Expression: _CtrIsValidHeapPointer(pUserData)

Why should this happen?
I am sure I have close the db connection and set the _RecordSetPrt and _ConnectionPrt to NULL

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

georgiek50Connect With a Mentor Commented:
I had lots of trouble with this one in the past.  It turns out that the reason for the crash and bug report was that I was trying to free memory again, meaning that the memory had already been freed from the pointer previously so trying to do it again resulted in the crash.  Look through your code to make sure you are not deleting twice.
can you upload the code in which you create the connection and the code for closing it?
jabbaaAuthor Commented:
The code I am using just as follows:

#include <stdio.h>
#include <afxdisp.h>
#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                 if (FAILED(_hr)) _com_issue_error(_hr); }

#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
   InitOle()  { ::CoInitialize(NULL); }
   ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE

void main(){
   _RecordsetPtr   spRS;
   _ConnectionPtr  spCON;
       spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;UID=sa; PWD=;";
       // spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=authors.MDB;DefaultDir=C:\\test;";
       spCON->Open( "", "", "", -1 );
       spRS->PutRefActiveConnection( spCON );
       spRS->Open("select au_lname, au_fname from authors",
              vtMissing, adOpenKeyset,
           adLockBatchOptimistic, -1
       while(spRS->adoEOF == false){
           printf("au_lname = %s  au_fname = %s \n",
                   UC _bstr_t(RsITEM(spRS,0L)),
                   UC _bstr_t(RsITEM(spRS,"au_fname"))
   catch( _com_error &e){
       _bstr_t bstrSource(e.Source());
       _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
           + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
           + _bstr_t(e.Description());
       MessageBox(0,bs,bstrSource, MB_OK);
look at this page:

debug your application, and when it's sopt on that line, go back on the stack to see the command and pointer which cause the problem.
All Courses

From novice to tech pro — start learning today.