Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_Block_Type_Is_Valid (pHead->nBlockUse) Error Message

Status
Not open for further replies.

cplsplsprogrammer

Programmer
Apr 18, 2005
42
US
Hello All,

I wrote a program that reads data from command line and inserts that data into the database using ADO. My program is running fine for two days and after that it is crashing throwing an exception given below

File: dbgdel.cpp line 52
Expression: _Block_Type_Is_Valid (pHead->nBlockUse)for information on how your program can cause an assertion failure, see the vc++ documentation on asserts


2) An application error has occurred

Exception: access violation (0xc0000005), Address: 0x77f7d4b1

I am using msado15.dll. I am pasting my code below, can anyone please tell me what I am doing wrong. I works fine when I compile, and deploy it on the server and it only crashes after two days.

I think the program is crashing in the below class.

my .cpp file class file

#include < stdio.h >
#include < windows.h >
#include < tchar.h >
#include < string.h >

#include "ReportReader.h"

_bstr_t ReportReader::Connect( _bstr_t memo, _bstr_t date )
{
//HRESULT hr = S_OK;

try
{
//this->AddToaMessageLog( "this is inside the database", 0, 0 );
_ConnectionPtr pConn( "ADODB.Connection" );
_RecordsetPtr pRst( "ADODB.Recordset" );

pConn.CreateInstance( (_uuidof( Connection )));

/*if( FAILED( hr ) )
{
//print error message
}*/

pRst.CreateInstance( (_uuidof( Recordset ) ));

//this->AddToaMessageLog( "instances created", 0, 0 );

/*if( FAILED( hr ) )
{
//print error message
}*/

strSQL = "Insert into Reports( memo, infoTime, Marked ) Values('";

strSQL += memo;
strSQL += "','";
strSQL += date;
strSQL += "', '0' )";

//this->AddToaMessageLog( strSQL, 0, 0 );


pConn->Open( "driver={SQL Server};Connect Timeout=60;server=myserver;"
"uid=user;pwd=mypwd;database=dbname",
"", "", adConnectUnspecified );

pRst->Open( strSQL,
pConn.GetInterfacePtr(), adOpenForwardOnly,
adLockReadOnly, adCmdText);

// pRst->MoveLast();
/// Note 2.
// printf("Last name is '%s %s'\n",
// (char*) ((_bstr_t) pRst->GetFields()->GetItem("au_fname")->GetValue()),
// (char*) ((_bstr_t) pRst->Fields->Item["au_lname"]->Value));
/*if( pRst )
pRst->Close();
if( pConn )
pConn->Close();*/

return( strSQL );
}
catch (_com_error &e)
{
wsprintf(error_string, "SQL connection exception Description = '%s'\n", (char*) e.Description());
error_code = e.Error();

_bstr_t errorMsg = error_string + error_code;

return( errorMsg );
}
return " ";
}


my ReportReader.h file....


#include <windows.h>

#import "msado15.dll" \
no_namespace rename("EOF", "EndOfFile")


class ReportReader
{
private:
char error_string[1024];
HRESULT error_code;
_bstr_t strSQL;

public:
ReportReader()
{
CoInitialize(NULL);

memset( error_string, 0, sizeof(error_string) );
error_code = 0x0;
}

~ReportReader()
{
::CoUninitialize();
}

_bstr_t Connect( _bstr_t memo, _bstr_t date );


char * LastError()
{
return error_string;
}

HRESULT LastErrorCode( )
{
return error_code;
}
};


Can anyone please tell me what I am doing wrong.



 
I don't see exactly what it is, but something is being deleted twice. When ever you do a delete, be sure to set the pointer to 0 so a second delete will not cause issue.

I'm not real com fluent, but you call pConn.CreateInstance(). Do you have to free it or destroy it?

Sometimes pasting the hex address from the error message in the memory window will show you what object is living at that address

Jeb
\0
 
Thank you Jeb. I will give a try using pConn.CreateInstance() and see if it works. I have to wait for two days and see if my program is working fine or not cause it if working fine for 2 days and crashing only after 48 hrs. I have it in a service and my service runs every hour.

--- RAM
 
You are already using pConn.CreateInstance but looks like you are not freeing it. You have to call Release() on the object when you are finished with it.

Why not run the program every 10 sec so you only have to wait 4 minutes for the crash.

jb
 
Thank you Jeb. My program works fine on the development box. That program is running fine from months on the development box, that has Windows XP on it. The production box is running on NT 4.0 and that is where the program is crashing, so I had to wait and see if it crashes on the production box. I am not sure if it would be something to do with the platform.

But the error I was getting before was because i was trying to free the memory twice, but I will still try to use Release()and see if it would fix it.

Thanks,
-- RAM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top