Debug Assertion Failure (daocore.cpp)

While exiting my application (exit(0)) I get this Assertion Failure. (I think) I closed all recordsets and the database. Could the problem have another origin than not closing the recordsets / database?

Here's the code where my application stops:
** daocore.cpp **
// ... you've not shut down with a call AfxDaoTerm()
ASSERT(m_pDAODBEngine == NULL);
**

Thanks.
StapmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abk102299Commented:
I don't think it's a good idea to exit MFC windows application with exit(0). In your case it seems the CWinApp::ExitInstance never been called. The data member m_lpfnDaoTerm of the CWinApp class usually stores the pointer to the AfxDaoTerm MFC's regular DAO termination function. That's where this assertion came from.

See MFC CWinApp::ExitInstance source code below:

int CWinApp::ExitInstance()
{
      // if we remember that we're unregistering,
      // don't save our profile settings

      if (m_pCmdInfo == NULL ||
            m_pCmdInfo->m_nShellCommand != CCommandLineInfo::AppUnregister)
      {
            if (!afxContextIsDLL)
                  SaveStdProfileSettings();
      }

      // Cleanup DAO if necessary
      if (m_lpfnDaoTerm != NULL)
      {
            // If a DLL, YOU must call AfxDaoTerm prior to ExitInstance
            ASSERT(!afxContextIsDLL);
            (*m_lpfnDaoTerm)();
      }

      return m_msgCur.wParam; // returns the value from PostQuitMessage
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abk102299Commented:
To close MFC windows application you ( for example ) can try to post the following message in the main frame window:

AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_APP_EXIT);
0
nietodCommented:
>> I don't think it's a good idea to exit MFC windows
>> application with exit(0)
Its not a good idea to exit ANY C++  application with exit()!.  Exit will not destroy local variables.  exit() is for extreme aborts, like error conditions.  but event then it should not be used.  You should throw an exception instead.  Basically, it should never be used.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

abk102299Commented:
>> I don't think it's a good idea to exit MFC windows
>> application with exit(0)

> Its not a good idea to exit ANY C++
> application with exit()!.  Exit will
> not destroy local variables.  exit()
> is for extreme aborts, like error
> conditions.  

I would say there is abort() for extreme aborts. But it doesn't seem to be the case - it looks as regular exit with no error code (0). In this case I wouldn't throw exception - it's overreaction :)

> but event then it should
> not be used.  You should throw an
> exception instead. Basically, it
> should never be used.

Never say never...

0
nietodCommented:
>> In this case I wouldn't throw exception
What case are you talking about?

>> Never say never...
I can't think of a reason to use it.  Can you?  You would have to justify failure to clean-up locals.  
0
abk102299Commented:
>> In this case I wouldn't throw exception
> What case are you talking about?

exit(0);
//  ^^^  0 error code returned

>> Never say never...

> I can't think of a reason to use it. > Can you?  You would have to justify
> failure to clean-up locals

Sometimes it's OK. You can find a lot of routines where exit(ne_ret) is used in the main() function implementation. But in general you are right, of course.
0
abk102299Commented:
Sorry, what I said is rather about return (ne_ret); Then NO, I don't have a reasonable example of the exit usage for now. Sometimes it's used in some temporary code - not for publishing, you know, but this is also doubtful practice.
0
nietodCommented:
exit(0);
//  ^^^  0 error code returned
Again you would be better of to throw an exception.  You can catch the exception in main and then use that to return the error code.  The exception object thrown can either be the error code or an object of a class that stores the error code.
0
abk102299Commented:
Wouldn't it be a little inefficient sometimes to enclose a program by a try/catch construct without a special reason for doing this?
0
nietodCommented:
>> without a special reason for doing this?
Yes!  I'm not proposing this as a "normal" way to exit.  Only as an "extreme" exit when an error is detected.  Sort of like calling exit() deep within the program, but safer because locals are destroyed.  A program should end by returning from main() under ordinary conditions, or perhaps by throwing an uncaught exception, under extreme conditions.  Other forms of exit (exit(), abort() TerminateProcess()), are really suspect.
0
StapmanAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.