From: Ambrish on
Hello All Members,

I have some problem with VC++ code. I have created a DLL having a
database class having connection pointer and recordset pointer. And I
have created Databse class (using ODBC) object into dllApp Class to
make it use like global object.
But when i call my dll and debug my dll i got exception at database
class destructor (while exiting fron DLL because this destructor is
called during the dll exitpoint).
//Databse.cpp
Datbase::~Database
{
newDSNptr=NULL; //_ConnectionPtr
newRECptr=NULL; //_RecordsetPtr ====>>>> Throws exception
::CoUninitialize();

}
Datbase::Database
{
::CoInitialize();
newDSNptr=NULL; //_ConnectionPtr
newRECptr=NULL; //_RecordsetPtr
try
{
newDSNptr.CreateInstance((__uuidof(Connection)));
newRECptr.CreateInstance((__uuidof(Recordset)));
newDSNptr->Open(L"Provider=MSDASQL.1;Persist Security
Info=False;DSN=NEW_DB_DSN;",L"",L"",0);
}
catch(_com_error &e)
{
AfxMessageBox(L"Error in New DataBse Connection\n" +
e.Description());
writeToFile(_T("CDatabase: ERROR: Error in New DataBse
Connection:"));
}
}
And in header file i have written like this
//Databse.h
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")

"First-chance exception in App.exe: 0xC0000005: Access Violation."
"First-chance exception in App.exe (MSDART.DLL): 0xC0000005: Access
Violation."

I have used all the try catch block for Database member function
operation to avoid any unhandelled exception. If anybody can help me i
will be very thankful to that people. i am in serious problem plz. help
me as soon as possible.

Thanks in advance.

Ambrish

From: Oleg Starodumov on

> I have some problem with VC++ code. I have created a DLL having a
> database class having connection pointer and recordset pointer. And I
> have created Databse class (using ODBC) object into dllApp Class to
> make it use like global object.
> But when i call my dll and debug my dll i got exception at database
> class destructor (while exiting fron DLL because this destructor is
> called during the dll exitpoint).

I would recommend to change the design and export additional functions
for initialization and cleanup of the database object. Doing initialization
(and especially cleanup) in the dll entry point is dangereous (e.g. because of
the possibility of deadlocks, race conditions (with cleanup of other components),
etc).

> I have used all the try catch block for Database member function
> operation to avoid any unhandelled exception.

I would also recommend to remove the try..catch blocks, at least temporarily.
It will ensure that you break into debugger as close to the actual reason of
the problem as possible (since even if the first exception gets handled but
the state of the component that raised the exception is destabilized, other
calls to the same component can raise exceptions too, but by that time you
will be already far from the original problem).

If the problem does not go away after these changes, please post
the call stack at the moment of the exception (preferrably with good
symbols).

Oleg
http://www.debuginfo.com/