Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have ocx in which iam initing the database and in that exit instance i wrote afxdaoint

function in the constructor of patricular list control i had init the database

and ocx exist instance i had called afxdaoterm but its looping ..i.e not closing the exe acces vialotion error came.

What I have tried:

if i used AfxDaoTerm in the exist instance its not closing the database its happening recursive what might be the problem.
Posted
Updated 3-Oct-17 21:12pm
v2
Comments
OriginalGriff 3-Oct-17 11:35am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So show us the code you are using, explain what is happening, and don't try to type as little as possible!
Help us to help you!

Use the "Improve question" widget to edit your question and provide better information.

1 solution

AfxDaoTerm is not closing the database. Quite the contrary it requires that all MFC DAO objects has been destroyed before calling it. Therefore you must not use instances of DAO objects but allocate them using new and delete them before calling AfxDaoTerm:
C++
CDaoDatabase *pDb = NULL;

// In InitInstance for global objects or function entry for local objects
pDb = new CDaoDatabase;

// Usage
pDb->Open();
// ...

// In ExitInstance for global objects or function exit for local objects
if (pDb)
{
    if (pDb->IsOpen())
        pDb->Close();
    delete pDb;
}

// ExitInstance
AfxDaoTerm();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900