读书人

ACCESS 频繁打开封锁后 打开失败

发布时间: 2013-02-19 11:11:40 作者: rapoo

ACCESS 频繁打开关闭后 打开失败
本帖最后由 killkun 于 2013-01-06 11:28:23 编辑


_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
CString connsStr(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="));
connsStr += m_dbName;
m_pConnection->Open((_bstr_t)connsStr,_T(""),_T(""),adModeUnknown);
}
catch(_com_error e)
{ //错误有一个线程,到一定的条件就调用此函数,在Access存贮20M内容左右,
运行56分钟后,会出现打开失败。此后就一直是打开失败
_bstr_t bstrDescription(e.Description());
CString strErro=(LPCSTR)e.Description();
CDebug::ShowDetailMessage(_T("open DB failed!"));
CDebug::ShowDetailMessage(strErro.GetBuffer());
strErro.ReleaseBuffer();
strErro = (LPCSTR)e.ErrorMessage();
CDebug::ShowDetailMessage(strErro.GetBuffer());

if(m_pConnection->State)
{
m_pConnection->Close();
m_pConnection.Release();
}
m_pConnection= NULL;

return FALSE;
}
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));

try
{
CString sql(_T("SELECT * FROM "));
sql = sql + m_dbTable;
m_pRecordset->Open((_variant_t)sql, // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
_bstr_t bstrDescription(e.Description());
CString err = (LPCSTR)e.Description();
CDebug::ShowDetailMessage(err.GetBuffer());
return FALSE;
}
try
{
//插入数据部分省略
m_pRecordset->Update();
}
catch(_com_error e)
{
_bstr_t bstrDescription(e.Description());
CString err = (LPCSTR)e.Description();
CDebug::ShowDetailMessage(err.GetBuffer());
}
m_pRecordset->Close();
m_pRecordset.Release();
m_pRecordset = NULL;

//关闭数据库
if(m_pConnection->State)
{
m_pConnection->Close();
m_pConnection.Release();
}
m_pConnection= NULL;

return TRUE;


//错误有一个线程,到一定的条件就调用此函数,在Access存贮20M内容左右,即运行56分钟后,会出现打开失败。此后就一直是打开失败 未指定的错误 ACCESS???频繁???打开??失败
[解决办法]
频繁打开关闭
我用文件频繁打开也出错!

读书人网 >VC/MFC

热点推荐