cplsplsprogrammer
Programmer
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 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.