I have encountered an issue and can't work out why it is happening.
Context:
- Windows 11
- Visual Studio 2022
- MFC Dialog 64 bit
- DEBUG mode
When I run the software in DEBUG mode, and perform a specific action (reading a ACCDB database) and then terminate the software, I get an exception.
I use the basic methods to open and close the database:
if (m_dbDatabase.OpenEx(strDBConnectString, CDatabase::noOdbcDialog))
{
m_pRecords = std::make_unique<CRecordset>(&m_dbDatabase);
}
And:
void CPTSDatabase::CloseDatabase()
{
if (m_dbDatabase.IsOpen())
m_dbDatabase.Close();
}
The database activity is operating correctly and not causing exceptions. Yet, when I terminate the software:
static void __cdecl try_cor_exit_process(UINT const return_code) throw()
{
__crt_unique_hmodule mscoree;
if (!GetModuleHandleExW(0, L"mscoree.dll", mscoree.get_address_of()))
return;
auto const cor_exit_process = __crt_get_proc_address<exit_process_pft>(mscoree.get(), "CorExitProcess");
if (!cor_exit_process)
return;
cor_exit_process(return_code);
}
I don't understand why did message is being displayed. My application InitInstance
and ExitInstance
both make reference to (respectively):
::CoInitialize(nullptr);
::CoUninitialize();
What I can confirm is that if I do not run the code that opens the database to read in and then close my application, I will not get this exception.
This is the Time Delay Debug entry:
Not sure how that helps me at this stage.
BTW. If I comment out CoUninitialize
it makes no difference. I sill get the error.
I don't know if it is related, when the OpenEx
call is performed on the database I debugged into it and noticed:
d:\a01_work\43\s\src\vctools\VC7Libs\Ship\ATLMFC\Src\MFC\dbcore.cpp(616) : AppMsg - Warning: ODBC Success With Info, d:\a01_work\43\s\src\vctools\VC7Libs\Ship\ATLMFC\Src\MFC\dbcore.cpp(174) : AppMsg - Driver's SQLSetConnectAttr failed
The actual function returned true though and gave me a valid database. I do not know if this message is part of the problem.
Update
I thought I would try a simple test project (dialog) and simply get it in the dialogs OnInitDialog to open my DB and then close it. Then I shut the test app down.
If I run this code in DEBUG x86:
if (db.OpenEx(_T("Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\My Documents\\Public Talks\\Public Talks.MDB;Pwd=~~~~"), CDatabase::noOdbcDialog))
{
AfxMessageBox(_T("DB Opened"));
db.Close();
}
And close that app down - no issues triggered.
But when I try this with DEBUG x64 and close it:
if (db.OpenEx(_T("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\\My Documents\\Public Talks\\Public Talks.ACCDB;Pwd=~~~~~"), CDatabase::noOdbcDialog))
{
AfxMessageBox(_T("DB Opened"));
db.Close();
}
Now that triggers: