我在 x64 应用程序中使用Microsoft Access 数据库引擎 2010(Microsoft Office 2016 的一部分)用于处理 mdb 文件。
但是,当前版本的 Microsoft Access Database Engine 2010(OLEDB 提供程序 Microsoft.ACE.OLEDB.12.0)有一个错误。
该引擎在多线程工作中崩溃。
如果我在不同的线程中创建与此提供程序的两个 OLE DB(或 ADO DB)连接,那么其中一个将崩溃Mso40UIwin32client.dll
异常 0xC0000005:访问冲突写入位置 0x0000000000000000。
异常堆栈:
- ACEOLEDBTest.exe 中的 0x00007FFB32361F28 处抛出异常:Microsoft
C++ 异常:内存位置处的 std::runtime_error
0x0000006B771FEAF0。
- 在 0x00007FFB32361F28 处抛出异常
ACEOLEDBTest.exe:Microsoft C++ 异常:[重新抛出] 内存
位置 0x0000000000000000。
- 0x00007FFB32361F28 处抛出异常
在 ACEOLEDBTest.exe 中:Microsoft C++ 异常:std::runtime_error at
内存位置 0x0000006B771FEAF0。
- 抛出异常
ACEOLEDBTest.exe 中的 0x00007FFB32361F28:Microsoft C++ 异常:
std::runtime_error 位于内存位置 0x0000006B771FEFB8。
- 例外
抛出于 0x00007FFAF9ED1271 (Mso40UIwin32client.dll)
ACEOLEDBTest.exe:0xC0000005:写入位置访问冲突
0x0000000000000000。
出现此错误的 C++ 代码示例:
#include "stdafx.h"
#include <atlcom.h>
#include <atldbcli.h>
#include <conio.h>
typedef UINT(__stdcall* fnThread)(PVOID);
HANDLE hExitEvent = NULL;
UINT __stdcall DbThread1(IN PVOID context)
{
HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hRes));
CDataSource DataSource; // Data source connection object
while (::WaitForSingleObject(hExitEvent, 0) != WAIT_OBJECT_0)
{
// Open DB connection
ATLTRACE2(atlTraceGeneral, 0, L"DbThread1: Create connection...\n");
hRes = DataSource.OpenFromInitializationString(L"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=\"C:\\Temp\\Index_empty1.mdb\"; Persist Security Info=False;");
_ASSERTE(SUCCEEDED(hRes));
// Close DB connection
DataSource.Close();
ATLTRACE2(atlTraceGeneral, 0, L"DbThread1: Close connection...\n");
Sleep(20);
}
::CoUninitialize();
_endthreadex(0);
return 0;
}
UINT __stdcall DbThread2(IN PVOID context)
{
HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hRes));
CDataSource DataSource; // Data source connection object
while (::WaitForSingleObject(hExitEvent, 0) != WAIT_OBJECT_0)
{
// Open DB connection
ATLTRACE2(atlTraceGeneral, 0, L"DbThread2: Create connection...\n");
hRes = DataSource.OpenFromInitializationString(L"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=\"C:\\Temp\\Index_empty2.mdb\"; Persist Security Info=False;");
_ASSERTE(SUCCEEDED(hRes));
// Close DB connection
DataSource.Close();
ATLTRACE2(atlTraceGeneral, 0, L"DbThread2: Close connection...\n");
Sleep(20);
}
::CoUninitialize();
_endthreadex(0);
return 0;
}
int main()
{
::CoInitializeEx(NULL, COINIT_MULTITHREADED);
hExitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
const fnThread aPtrs[] = { DbThread1, DbThread2 };
HANDLE hDbThread[_countof(aPtrs)] = { NULL };
for (int nIndex = 0; nIndex < _countof(aPtrs); nIndex++) {
if ((hDbThread[nIndex] = (HANDLE)::_beginthreadex(nullptr, 0, aPtrs[nIndex], nullptr, 0, nullptr)) == NULL)
{
return 1;
}
}
CComVariant varData;
printf("Press any key to exit...");
// Loop until any key struck
while (!_kbhit())
{
for (DWORD i = 0; i < 100; i++)
{
// Test for bug of the OLEDB provider for MS ACCESS 2010.
varData.Clear();
}
Sleep(0);
}
// Request threads to exit
SetEvent(hExitEvent);
// Wait for threads to exit
WaitForMultipleObjects(_countof(hDbThread), hDbThread, TRUE, INFINITE);
for (auto& h : hDbThread) {
CloseHandle(h);
}
CloseHandle(hExitEvent);
::CoUninitialize();
return 0;
}
您应该使用 Visual C++ 2013/2015 为 x64 平台构建此示例。
我在以下位置发现了类似的错误MS forum。有谁能够帮助我?