I have this code:
DManag::~DManag() {
printf("in dest\n");
if(mainConn.IsOpen()) {
printf("about to close\n");
mainConn.Close();
printf("closed!\n");
}
printf("end dest\n");
}
The output is: in dest \n about to close \n and that is it.
It (mainConn -> CDatabase class) seems to silently fail upon calling close(). I know you are supposed to close connections as soon as you are done with them. But I inherited this code from someone else, but the program does not provide an easy way to close the connection at the right time. Close() and open() calls are located in afxdb.h.
Any idea why it might fail like this? Thanks!
The problem appears to be that
CDatabase::Closeis throwing an exception and causing the rest of the destructor to be bypassed. The documentation doesn’t mention this method can throw but other usage samples on the internet indicate that it can.Try modifying the destructor as follows