16,471
社区成员
发帖
与我相关
我的任务
分享
BOOL CDBBase::OpenDatabase()
{
HRESULT hr = S_OK;
m_pConnection.CreateInstance("ADODB.Connection");
try{
if( m_pConnection==NULL )
TESTHR(m_pConnection.CreateInstance(__uuidof(Connection)));
if( m_pConnection->GetState()==adStateClosed )
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=ChargeDB.mdb", "","",adModeUnknown);
}catch(_com_error& e){
CloseDatabase();
LOG_Write(g_hLog,"CDBBase::OpenDatabase failed:%s",e.ErrorMessage());
return false;
}
return true;
}
CoInitialize(NULL);
CString strSql(_T(""));
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
CString strConn(_T(""));
strSql.Format("select xxx from xxx_tb where id = '101'");
CString strFile;
strFile.Format("C:\\test.mdb");
strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=%s", strFile);
pConn->ConnectionString = _bstr_t(strConn);
try
{
if ( pConn->Open("", "", "", adCmdUnspecified) != 0 )
return FALSE;
pRst->Open(_variant_t(strSql), _variant_t(pConn,true), adOpenDynamic, adLockPessimistic, adCmdText);
...
}
...