各位大佬,請問一下:在MFC ADO下連接Access資料庫Open失敗,提示未指定的錯誤,這是什么原因導致的呢?
代碼如下:
在stdafx.h添加
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF", "adoEOF")
在CTestApp.cpp添加
BOOL CTestApp::InitInstance()
{
AfxEnableControlContainer();
if (!AfxOleInit())
{
AfxMessageBox(L"初始化OLE DLL失敗");
return FALSE;
}
}
在CTestDlg.h添加
_ConnectionPtr m_pConnection;
在CTestDlg.cpp添加
BOOL CTestDlg::OnInitDialog()
{
HRESULT hr;
try {
hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
hr = m_pConnection->Open("E:\\database\\test.accdb", "", "", adModeUnknown);
}
}
catch (_com_error e)
{
CString errorMessage;
errorMessage.Format(_T("Connect db failed:%s"), e.ErrorMessage());//此處提示“未指定的錯誤”
AfxMessageBox(errorMessage);
}
}
如上代碼,懇請給位大佬,指點一下,到底哪里錯了,為什么連打開Access資料庫都會報錯呢?小弟在此,不勝感激。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/280399.html
標籤:基礎類
