_CtrIsValidHeapPointer(pUserData) problem

Posted on 2003-03-16
Medium Priority
Last Modified: 2012-08-13
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

Question by:jabbaa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 8146178
can you upload the code in which you create the connection and the code for closing it?

Author Comment

ID: 8146278
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);

Expert Comment

ID: 8146360
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.

Accepted Solution

georgiek50 earned 150 total points
ID: 8147780
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.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question