7,714
社区成员
发帖
与我相关
我的任务
分享
rc->Open(bstrSQL,
pConn.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
//这句执行直接出错,中断了运行,根本进不了catch,MY GOD
std::string strHisDbPath = theApp.m_SystemSetInfo.szHisDbStorePath;
//strHisDbPath += "\\";
strHisDbPath += theApp.m_SystemSetInfo.ExistSystemSet.szCurrentSysName;
strHisDbPath += ".mdb";
CString strConn(_T("Provider=Microsoft.JET.OLEDB.4.0;Data source = "));
strConn += strHisDbPath.c_str();
::CoInitialize(NULL);
HRESULT hr = S_OK;
if (!CFileHelper::IsFileExist(strHisDbPath.c_str()))
{
//if db file not exist,then create it
try
{
ADOX::_CatalogPtr pCatalog = NULL;
hr = pCatalog.CreateInstance(__uuidof (ADOX::Catalog));
if(FAILED(hr))
{
_com_issue_error(hr);
}
else
{
pCatalog->Create(_bstr_t(strConn)); //Create mdb
}
}
catch(_com_error *e)
{
TRACE(e->ErrorMessage());
::CoUninitialize();
return FALSE;
}
}
_ConnectionPtr pConn;
try
{
//Create table
pConn.CreateInstance(__uuidof(Connection));
pConn->Open(_bstr_t(strConn), "", "", adConnectUnspecified);
_RecordsetPtr rc ;
rc.CreateInstance(__uuidof(Recordset));
_variant_t RecordsAffected;
CString strSql,strTableName,strTemp;
strTemp = "select * from ";
BSTR bstrSQL;
for (int i = 0; i < theApp.m_StationSystem.StationTagVector.size(); i++)
{
strTableName = theApp.m_StationSystem.StationTagVector.at(i).szTagName;
//rc = pConn->OpenSchema(adSchemaTables);
strSql = strTemp + strTableName;
bstrSQL = strSql.AllocSysString();
try
{
rc->Open(bstrSQL,
pConn.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
// pConn->Execute(bstrSQL,&RecordsAffected,adCmdText);
}
catch (_com_error* e)
{
TRACE(e->ErrorMessage());//这里不进来了,直接在上面的OPEN函数执行时出错了
}
//hr = pConn->Execute(bstrSQL, &RecordsAffected, adCmdText);
}
}
catch (_com_error* e)
{
TRACE(e->ErrorMessage());
pConn = NULL;
::CoUninitialize();
return FALSE;
}
pConn->Close();
pConn = NULL;
::CoUninitialize();