try{
CADORecordset pRst(&gADODB);这个库是carlos antollini 写的一个cpp
CString str;
if(strID.GetLength() )
{
str.Format("select * from WYS.MSG_MAIL_TAB where msg_time > %s and msg_configid = %s",strTime,strID);
}
else
{
str.Format("select * from WYS.MSG_MAIL_TAB where msg_time > %s",strTime );
}
if(strMail.GetLength())
{
CString strtemp = " and (msg_frombox like '\%";
strtemp +=strMail;
strtemp +="\%' or msg_tobox like '\%";
strtemp += strMail;
strtemp +="\%')";
str += strtemp;
}
//str.Format("select * from WYS.MSG_MAIL_TAB where msg_uniqueid = 1854983");
pRst.Open(str.GetBuffer(str.GetLength()));
//int i = pRst.GetRecordCount();
pRst.MoveFirst();               //在这里出现错误。 DWORD dwID,dwOffset,dwLen;
CString strFileName;
CString LastFileName ="";
//FileInfo fileinfo;
//CString strSourceDir = "e:\\";
HANDLE hSourceFile=0, hDestFile=0;
while(!pRst.IsEOF())
{
pRst.GetFieldValue("msg_uniqueid",dwID);
pRst.GetFieldValue("hf_name",strFileName);
pRst.GetFieldValue("hf_msgoffset",dwOffset);
pRst.GetFieldValue("msg_Length",dwLen);
if(strFileName != LastFileName)
{
LastFileName = strFileName;
if(hSourceFile && (hSourceFile!=INVALID_HANDLE_VALUE))
{
CloseHandle(hSourceFile);
hSourceFile = 0;
hSourceFile = Openfile(false, strDataDir + strFileName);
if(hSourceFile == INVALID_HANDLE_VALUE)
{
//AfxMessageBox(strSourceDir + strFileName);
continue;
}
}
}
if(!hSourceFile || (hSourceFile==INVALID_HANDLE_VALUE))
{
hSourceFile = Openfile(false, strDataDir + strFileName);
if(hSourceFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox(strDataDir + strFileName);
continue;
}
}
CString strPath;
strPath.Format("%s\\%u.eml",strDir, dwID);
hDestFile = Openfile(true, strPath);
WriteEmlFile(hSourceFile,hDestFile,dwOffset,dwLen);
pRst.MoveNext();
}
pRst.Close();
}
catch(_com_error& e)
{
CString str;
str.Format("错误信息:%s",e.ErrorMessage());
//AfxMessageBox(str);
return ;
}有时候出错,有时候不出错,我在检查sql语句是正确的。