使用 ACCESS 和 ADO 无法识别的数据库格式
Unrecognised database format with ACCESS and ADO
全部,
我有一个 MS Access accdb 文件,我尝试连接到该文件:
std::wstring dbFile = pimpl->m_connectString.substr( pimpl->m_connectString.find( L"DBQ=") + 4 );
dbFile = dbFile.substr( 0, dbFile.find( L";" ) );
if( FAILED( CoInitialize( NULL ) ) )
{
errorMsg.push_back( L"Failed to initialize DAO interface" );
result = 1;
}
if( !result )
{
LPCSTR version;
std::wstring connectString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
connectString += dbFile;
_bstr_t strCnn( connectString.c_str() );
_ConnectionPtr pConnection = NULL;
try
{
if( FAILED( pConnection.CreateInstance( __uuidof( Connection ) ) ) )
{
errorMsg.push_back( L"Failed to create a connection to ACCESS engine" );
result = 1;
}
else
{
pConnection->Open( strCnn, "", "", adConnectUnspecified );
version = (LPCSTR) (_bstr_t) pConnection->Properties->GetItem("DBMS Version")->Value;
}
}
catch( _com_error &e )
{
ErrorPtr pErr = NULL;
if( ( pConnection->Errors->Count ) > 0 )
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for( long i = 0 ; i < nCount ; i++ )
{
std::wstring error = L"Error is ";
pErr = pConnection->Errors->GetItem( i );
std::string descr( ((LPCSTR) pErr->Description) );
printf( "Error number: %x\t%s\n", pErr->Number, (LPCSTR) pErr->Description );
}
}
}
CoUninitialize();
但是在执行时出现上述错误。
我错过了什么?
我正在 Windows 8.1.
与 MSVC 2017 社区合作
我不知道文件是用什么引擎创建的。
TIA!
您可能使用了错误的提供商。对于 accdb 文件,请使用以下内容:
Provider=Microsoft.ACE.OLEDB.12.0;Data
Sourcee=C:\myFolder\myAccessFile.accdb;Persist
Security Info=False;
您可能必须安装所需的 ACE 驱动程序,可从 M$ 站点免费获得。
全部,
我有一个 MS Access accdb 文件,我尝试连接到该文件:
std::wstring dbFile = pimpl->m_connectString.substr( pimpl->m_connectString.find( L"DBQ=") + 4 );
dbFile = dbFile.substr( 0, dbFile.find( L";" ) );
if( FAILED( CoInitialize( NULL ) ) )
{
errorMsg.push_back( L"Failed to initialize DAO interface" );
result = 1;
}
if( !result )
{
LPCSTR version;
std::wstring connectString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
connectString += dbFile;
_bstr_t strCnn( connectString.c_str() );
_ConnectionPtr pConnection = NULL;
try
{
if( FAILED( pConnection.CreateInstance( __uuidof( Connection ) ) ) )
{
errorMsg.push_back( L"Failed to create a connection to ACCESS engine" );
result = 1;
}
else
{
pConnection->Open( strCnn, "", "", adConnectUnspecified );
version = (LPCSTR) (_bstr_t) pConnection->Properties->GetItem("DBMS Version")->Value;
}
}
catch( _com_error &e )
{
ErrorPtr pErr = NULL;
if( ( pConnection->Errors->Count ) > 0 )
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for( long i = 0 ; i < nCount ; i++ )
{
std::wstring error = L"Error is ";
pErr = pConnection->Errors->GetItem( i );
std::string descr( ((LPCSTR) pErr->Description) );
printf( "Error number: %x\t%s\n", pErr->Number, (LPCSTR) pErr->Description );
}
}
}
CoUninitialize();
但是在执行时出现上述错误。
我错过了什么?
我正在 Windows 8.1.
与 MSVC 2017 社区合作我不知道文件是用什么引擎创建的。
TIA!
您可能使用了错误的提供商。对于 accdb 文件,请使用以下内容:
Provider=Microsoft.ACE.OLEDB.12.0;Data
Sourcee=C:\myFolder\myAccessFile.accdb;Persist
Security Info=False;
您可能必须安装所需的 ACE 驱动程序,可从 M$ 站点免费获得。