Hi there,
I've developed an app in BCB5 that queries a SQL database and an Access database every 60 seconds to see if there are any reports due to run. The problem is, every time the timer fires and the code is run, the memory usage increases from 70K to 200K. I am new to C++ in general so can anyone tell me if I am not closing or deleting the proper objects. I won;t post all the code cause it's long - just the pertinent stuff. Also, I don't know what this means but if I minimize the app then maximize it again, the memory jumps back down to what it started at (approx 5MB). Thanks:
//only check DocuCentral reports if .ini exists
//these reports are stored in SQL database
if(dcExists==true){
//Get DSN info from DCOptions.ini
AnsiString tmpDSN;
AnsiString tmpUserID;
AnsiString tmpPassword;
AnsiString tmpIC;
AnsiString dcRoot;
AnsiString iniLoc = ExtractFileDir(ParamStr(0))+"\\DCOptions.ini";
AnsiString homeDir = ExtractFileDir(ParamStr(0));
TIniFile *ini;
ini = new TIniFile( iniLoc );
tmpDSN = ini->ReadString ( "DocuCentral DB Settings", "DSN", "" );
tmpUserID = Decrypt(ini->ReadString ( "DocuCentral DB Settings", "User ID", "" ).c_str());
tmpPassword = Decrypt(ini->ReadString ( "DocuCentral DB Settings", "Password", "" ).c_str());
tmpIC = ini->ReadString ( "DocuCentral DB Settings", "Initial Catalog", ""
dcRoot = ini->ReadString ( "DocuCentral DB Settings", "Root Dir", ""
delete ini;
//See if any reports are due to run
TCOM_Recordset RsTemp = CoRecordset::Create();
TCOM_Recordset RsTemp2 = CoRecordset::Create();
TCOM_Recordset RsTemp3 = CoRecordset::Create();
TCOM_Recordset RsTemp4 = CoRecordset::Create();
//check Every Reports
RsTemp->Open(
WideString("SELECT * FROM Reports_Scheduled_Every WHERE Start_Date <= GetDate() AND End_Date >= GetDate()".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockOptimistic,
Adodb_tlb::adCmdText
);
while ( !bool(RsTemp->EOF) )
{
if(StrToDateTime(RsTemp->Fields->get_Item(6)->get_Value()) + Double(RsTemp->Fields->get_Item(5)->get_Value()) <= Now())
{
AnsiString index = RsTemp->Fields->get_Item(0)->get_Value();
AnsiString rptName = Trim(RsTemp->Fields->get_Item(1)->get_Value());
AnsiString newExt = "_"+FormatDateTime("mmddyyyy_hhmm", Now());
AnsiString saveName;
AnsiString jobName = Trim(RsTemp->Fields->get_Item(9)->get_Value());
AnsiString email = Trim(RsTemp->Fields->get_Item(10)->get_Value());
TCrExportType exportType;
int isCustom = 0;
if (RsTemp->Fields->get_Item(7)->get_Value() == true)
{
isCustom = 1;
}
switch (StrToInt(Trim(RsTemp->Fields->get_Item(8)->get_Value())))
{
case 1:
exportType = ExcelXLS;
saveName = jobName+newExt+".xls";
break;
case 2:
exportType = HTML4;
saveName = jobName+newExt+".htm";
break;
case 3:
exportType = AdobeAcrobatPDF;
saveName = jobName+newExt+".pdf";
break;
case 4:
exportType = WordForWindows;
saveName = jobName+newExt+".doc";
break;
}
CrScheduler->ReportName = dcRoot+"\\Reports\\"+rptName;
CrScheduler->Output = toExport;
CrScheduler->ExportOptions->FileType = exportType;
CrScheduler->ExportOptions->Destination = toFile;
CrScheduler->ExportOptions->FileName = dcRoot+"\\Reports\\"+saveName;
//get Parameters, if any
RsTemp3->Open(
WideString("SELECT * FROM Params_Reports_Every WHERE Reports_Scheduled_Every_Index = "+RsTemp->Fields->get_Item(0)->get_Value()+" ORDER BY Param_Index".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
int paramNum = 0;
while (!bool(RsTemp3->EOF))
{
CrScheduler->ParamFields->Items[paramNum]->CurrentValue=Trim(RsTemp3->Fields->get_Item(4)->get_Value());
paramNum++;
RsTemp3->MoveNext();
}
RsTemp3->Close();
//run report
Memo1->Lines->Add(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+rptName+" - "+saveName);
WriteLog(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+rptName+" - "+saveName);
CrScheduler->Execute();
//add report to Documents
RsTemp3->Open(
WideString("INSERT INTO Documents VALUES('"+saveName+"', '"+jobName+"',"+isCustom+"".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp3->Close();
//add permissions if custom
if(isCustom == 1)
{
//get index of record just added
RsTemp3->Open(
WideString("SELECT Documents_Index FROM Documents WHERE Name = '"+saveName+"'".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
//get permissions from Groups_Scheduled_Every_Permissions
RsTemp2->Open(
WideString("SELECT Groups_Index FROM Groups_Scheduled_Every_Permissions WHERE Reports_Scheduled_Every_Index ="+index ).Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
//add permissions to Groups_Documents_Permissions if Custom
while (!bool(RsTemp2->EOF))
{
RsTemp4->Open(
WideString("INSERT INTO Groups_Documents_Permissions VALUES("+RsTemp2->Fields->get_Item(0)->get_Value()+", "+RsTemp3->Fields->get_Item(0)->get_Value()+"".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->MoveNext();
}
RsTemp2->Close();
RsTemp3->Close();
RsTemp4->Close();
}
//email if necessary
if(email != "None"
{
CrScheduler->ExportOptions->Destination = toEmailViaMapi;
CrScheduler->ExportOptions->Email->ToList = email;
CrScheduler->ExportOptions->Email->Subject="Scheduled Report - "+saveName;
CrScheduler->Execute();
}
//update last_run
RsTemp2->Open(
WideString("UPDATE Reports_Scheduled_Every SET Last_Run = '"+Now()+"' WHERE Reports_Scheduled_Every_Index = "+index).Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->Close();
}
RsTemp->MoveNext();
}
RsTemp->Close();
//check first/last reports
{
<b>snip checking of 2 more report types in SQL DB></b>
}
//when done checking reports and exporting
RsTemp->Close();
delete RsTemp;
delete RsTemp2;
delete RsTemp3;
delete RsTemp4;
CrScheduler->Clear();
}
//begin checking normal reports
//these are stored in Access DB
TCOM_Recordset RsTemp = CoRecordset::Create();
TCOM_Recordset RsTemp2 = CoRecordset::Create();
//check Every Reports
RsTemp->Open(
WideString("SELECT * FROM Reports_Every WHERE Start_Date <= Now() AND End_Date >= Now()".Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockOptimistic,
Adodb_tlb::adCmdText
);
while ( !bool(RsTemp->EOF) )
{
if(StrToDateTime(RsTemp->Fields->get_Item(6)->get_Value()) + Double(RsTemp->Fields->get_Item(8)->get_Value()) <= Now())
{
AnsiString index = RsTemp->Fields->get_Item(0)->get_Value();
AnsiString path = Trim(RsTemp->Fields->get_Item(1)->get_Value());
AnsiString jobName = Trim(RsTemp->Fields->get_Item(2)->get_Value());
AnsiString newExt = "_"+FormatDateTime("mmddyyyy_hhmm", Now());
AnsiString savePath = Trim(RsTemp->Fields->get_Item(3)->get_Value());
AnsiString email = Trim(RsTemp->Fields->get_Item(9)->get_Value());
int format = RsTemp->Fields->get_Item(7)->get_Value();
AnsiString saveName;
TCrExportType exportType;
switch (format)
{
case 1:
exportType = ExcelXLS;
saveName=savePath+"\\"+jobName+newExt+".xls";
break;
case 2:
exportType=HTML4;
saveName=savePath+"\\"+jobName+newExt+".htm";
break;
case 3:
exportType=AdobeAcrobatPDF;
saveName=savePath+"\\"+jobName+newExt+".pdf";
break;
case 4:
exportType=WordForWindows;
saveName=savePath+"\\"+jobName+newExt+".doc";
break;
}
Cr1->ReportName = path;
Cr1->Output = toExport;
Cr1->ExportOptions->FileType = exportType;
Cr1->ExportOptions->Destination = toFile;
Cr1->ExportOptions->FileName = saveName;
//get Parameters, if any
RsTemp2->Open(
WideString("SELECT * FROM Params_Every WHERE Reports_Every_Index = "+index+" ORDER BY Param_Index".Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
int paramNum = 0;
while (!bool(RsTemp2->EOF))
{
Cr1->ParamFields->Items[paramNum]->CurrentValue=Trim(RsTemp2->Fields->get_Item(4)->get_Value());
paramNum++;
RsTemp2->MoveNext();
}
RsTemp2->Close();
//run report
Memo1->Lines->Add(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+path+" - "+saveName);
WriteLog(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+path+" - "+saveName);
Cr1->Execute();
//email if necessary
if(email != "None"
{
Cr1->ExportOptions->Destination = toEmailViaMapi;
Cr1->ExportOptions->Email->ToList = email;
Cr1->ExportOptions->Email->Subject="Scheduled Report - "+saveName;
Cr1->Execute();
}
//update last_run
RsTemp2->Open(
WideString("UPDATE Reports_Every SET Last_Run = '"+Now()+"' WHERE Reports_Every_Index = "+index).Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->Close();
}
RsTemp->MoveNext();
}
RsTemp->Close();
//check Nth reports
{
<b><snip checking of 2 more report types></b>
}
RsTemp->Close();
delete RsTemp;
delete RsTemp2;
Cr1->Clear();
bttnMainStop->Enabled = true;
I've developed an app in BCB5 that queries a SQL database and an Access database every 60 seconds to see if there are any reports due to run. The problem is, every time the timer fires and the code is run, the memory usage increases from 70K to 200K. I am new to C++ in general so can anyone tell me if I am not closing or deleting the proper objects. I won;t post all the code cause it's long - just the pertinent stuff. Also, I don't know what this means but if I minimize the app then maximize it again, the memory jumps back down to what it started at (approx 5MB). Thanks:
//only check DocuCentral reports if .ini exists
//these reports are stored in SQL database
if(dcExists==true){
//Get DSN info from DCOptions.ini
AnsiString tmpDSN;
AnsiString tmpUserID;
AnsiString tmpPassword;
AnsiString tmpIC;
AnsiString dcRoot;
AnsiString iniLoc = ExtractFileDir(ParamStr(0))+"\\DCOptions.ini";
AnsiString homeDir = ExtractFileDir(ParamStr(0));
TIniFile *ini;
ini = new TIniFile( iniLoc );
tmpDSN = ini->ReadString ( "DocuCentral DB Settings", "DSN", "" );
tmpUserID = Decrypt(ini->ReadString ( "DocuCentral DB Settings", "User ID", "" ).c_str());
tmpPassword = Decrypt(ini->ReadString ( "DocuCentral DB Settings", "Password", "" ).c_str());
tmpIC = ini->ReadString ( "DocuCentral DB Settings", "Initial Catalog", ""
dcRoot = ini->ReadString ( "DocuCentral DB Settings", "Root Dir", ""
delete ini;
//See if any reports are due to run
TCOM_Recordset RsTemp = CoRecordset::Create();
TCOM_Recordset RsTemp2 = CoRecordset::Create();
TCOM_Recordset RsTemp3 = CoRecordset::Create();
TCOM_Recordset RsTemp4 = CoRecordset::Create();
//check Every Reports
RsTemp->Open(
WideString("SELECT * FROM Reports_Scheduled_Every WHERE Start_Date <= GetDate() AND End_Date >= GetDate()".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockOptimistic,
Adodb_tlb::adCmdText
);
while ( !bool(RsTemp->EOF) )
{
if(StrToDateTime(RsTemp->Fields->get_Item(6)->get_Value()) + Double(RsTemp->Fields->get_Item(5)->get_Value()) <= Now())
{
AnsiString index = RsTemp->Fields->get_Item(0)->get_Value();
AnsiString rptName = Trim(RsTemp->Fields->get_Item(1)->get_Value());
AnsiString newExt = "_"+FormatDateTime("mmddyyyy_hhmm", Now());
AnsiString saveName;
AnsiString jobName = Trim(RsTemp->Fields->get_Item(9)->get_Value());
AnsiString email = Trim(RsTemp->Fields->get_Item(10)->get_Value());
TCrExportType exportType;
int isCustom = 0;
if (RsTemp->Fields->get_Item(7)->get_Value() == true)
{
isCustom = 1;
}
switch (StrToInt(Trim(RsTemp->Fields->get_Item(8)->get_Value())))
{
case 1:
exportType = ExcelXLS;
saveName = jobName+newExt+".xls";
break;
case 2:
exportType = HTML4;
saveName = jobName+newExt+".htm";
break;
case 3:
exportType = AdobeAcrobatPDF;
saveName = jobName+newExt+".pdf";
break;
case 4:
exportType = WordForWindows;
saveName = jobName+newExt+".doc";
break;
}
CrScheduler->ReportName = dcRoot+"\\Reports\\"+rptName;
CrScheduler->Output = toExport;
CrScheduler->ExportOptions->FileType = exportType;
CrScheduler->ExportOptions->Destination = toFile;
CrScheduler->ExportOptions->FileName = dcRoot+"\\Reports\\"+saveName;
//get Parameters, if any
RsTemp3->Open(
WideString("SELECT * FROM Params_Reports_Every WHERE Reports_Scheduled_Every_Index = "+RsTemp->Fields->get_Item(0)->get_Value()+" ORDER BY Param_Index".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
int paramNum = 0;
while (!bool(RsTemp3->EOF))
{
CrScheduler->ParamFields->Items[paramNum]->CurrentValue=Trim(RsTemp3->Fields->get_Item(4)->get_Value());
paramNum++;
RsTemp3->MoveNext();
}
RsTemp3->Close();
//run report
Memo1->Lines->Add(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+rptName+" - "+saveName);
WriteLog(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+rptName+" - "+saveName);
CrScheduler->Execute();
//add report to Documents
RsTemp3->Open(
WideString("INSERT INTO Documents VALUES('"+saveName+"', '"+jobName+"',"+isCustom+"".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp3->Close();
//add permissions if custom
if(isCustom == 1)
{
//get index of record just added
RsTemp3->Open(
WideString("SELECT Documents_Index FROM Documents WHERE Name = '"+saveName+"'".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
//get permissions from Groups_Scheduled_Every_Permissions
RsTemp2->Open(
WideString("SELECT Groups_Index FROM Groups_Scheduled_Every_Permissions WHERE Reports_Scheduled_Every_Index ="+index ).Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
//add permissions to Groups_Documents_Permissions if Custom
while (!bool(RsTemp2->EOF))
{
RsTemp4->Open(
WideString("INSERT INTO Groups_Documents_Permissions VALUES("+RsTemp2->Fields->get_Item(0)->get_Value()+", "+RsTemp3->Fields->get_Item(0)->get_Value()+"".Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->MoveNext();
}
RsTemp2->Close();
RsTemp3->Close();
RsTemp4->Close();
}
//email if necessary
if(email != "None"
{
CrScheduler->ExportOptions->Destination = toEmailViaMapi;
CrScheduler->ExportOptions->Email->ToList = email;
CrScheduler->ExportOptions->Email->Subject="Scheduled Report - "+saveName;
CrScheduler->Execute();
}
//update last_run
RsTemp2->Open(
WideString("UPDATE Reports_Scheduled_Every SET Last_Run = '"+Now()+"' WHERE Reports_Scheduled_Every_Index = "+index).Detach(),
WideString("Provider=SQL OLEDB;User ID="+tmpUserID.Trim()+";Password="+tmpPassword.Trim()+";Initial Catalog="+tmpIC.Trim()+";Data Source="+tmpDSN.Trim()).Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->Close();
}
RsTemp->MoveNext();
}
RsTemp->Close();
//check first/last reports
{
<b>snip checking of 2 more report types in SQL DB></b>
}
//when done checking reports and exporting
RsTemp->Close();
delete RsTemp;
delete RsTemp2;
delete RsTemp3;
delete RsTemp4;
CrScheduler->Clear();
}
//begin checking normal reports
//these are stored in Access DB
TCOM_Recordset RsTemp = CoRecordset::Create();
TCOM_Recordset RsTemp2 = CoRecordset::Create();
//check Every Reports
RsTemp->Open(
WideString("SELECT * FROM Reports_Every WHERE Start_Date <= Now() AND End_Date >= Now()".Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockOptimistic,
Adodb_tlb::adCmdText
);
while ( !bool(RsTemp->EOF) )
{
if(StrToDateTime(RsTemp->Fields->get_Item(6)->get_Value()) + Double(RsTemp->Fields->get_Item(8)->get_Value()) <= Now())
{
AnsiString index = RsTemp->Fields->get_Item(0)->get_Value();
AnsiString path = Trim(RsTemp->Fields->get_Item(1)->get_Value());
AnsiString jobName = Trim(RsTemp->Fields->get_Item(2)->get_Value());
AnsiString newExt = "_"+FormatDateTime("mmddyyyy_hhmm", Now());
AnsiString savePath = Trim(RsTemp->Fields->get_Item(3)->get_Value());
AnsiString email = Trim(RsTemp->Fields->get_Item(9)->get_Value());
int format = RsTemp->Fields->get_Item(7)->get_Value();
AnsiString saveName;
TCrExportType exportType;
switch (format)
{
case 1:
exportType = ExcelXLS;
saveName=savePath+"\\"+jobName+newExt+".xls";
break;
case 2:
exportType=HTML4;
saveName=savePath+"\\"+jobName+newExt+".htm";
break;
case 3:
exportType=AdobeAcrobatPDF;
saveName=savePath+"\\"+jobName+newExt+".pdf";
break;
case 4:
exportType=WordForWindows;
saveName=savePath+"\\"+jobName+newExt+".doc";
break;
}
Cr1->ReportName = path;
Cr1->Output = toExport;
Cr1->ExportOptions->FileType = exportType;
Cr1->ExportOptions->Destination = toFile;
Cr1->ExportOptions->FileName = saveName;
//get Parameters, if any
RsTemp2->Open(
WideString("SELECT * FROM Params_Every WHERE Reports_Every_Index = "+index+" ORDER BY Param_Index".Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
int paramNum = 0;
while (!bool(RsTemp2->EOF))
{
Cr1->ParamFields->Items[paramNum]->CurrentValue=Trim(RsTemp2->Fields->get_Item(4)->get_Value());
paramNum++;
RsTemp2->MoveNext();
}
RsTemp2->Close();
//run report
Memo1->Lines->Add(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+path+" - "+saveName);
WriteLog(FormatDateTime("mm/dd/yyyy hh:mm:ss", Now())+" - "+jobName+" - "+path+" - "+saveName);
Cr1->Execute();
//email if necessary
if(email != "None"
{
Cr1->ExportOptions->Destination = toEmailViaMapi;
Cr1->ExportOptions->Email->ToList = email;
Cr1->ExportOptions->Email->Subject="Scheduled Report - "+saveName;
Cr1->Execute();
}
//update last_run
RsTemp2->Open(
WideString("UPDATE Reports_Every SET Last_Run = '"+Now()+"' WHERE Reports_Every_Index = "+index).Detach(),
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ExtractFileDir(ParamStr(0))+"\\dcScheduler.mdb;Persist Security Info = False".Detach(),
Adodb_tlb::adOpenKeyset,
Adodb_tlb::adLockPessimistic,
Adodb_tlb::adCmdText
);
RsTemp2->Close();
}
RsTemp->MoveNext();
}
RsTemp->Close();
//check Nth reports
{
<b><snip checking of 2 more report types></b>
}
RsTemp->Close();
delete RsTemp;
delete RsTemp2;
Cr1->Clear();
bttnMainStop->Enabled = true;