ACCESS 频繁打开关闭后 打开失败

小坤 小坤 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

_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分钟后,会出现打开失败。此后就一直是打开失败 未指定的错误
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
小坤
数据库 4,017 成员 39,805 内容