Refresh causing Query Engine Error
Dear folks,
I was trying to write a .Net web application (using C#) that loads a Crystal
Report on server side, export the report in PDF format as a file in the web
server, and then serves up the file for clients to download. My code was
working so far so good until I added ONE line.
Here's my working code so far:
---------------- (code start) -------------------------
System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog();
try
{
DiskFileDestinationOptions dFileDOpts = new DiskFileDestinationOptions();
//string sSrcPath = this.MapPath("./BigReportTest.rpt");
string sSrcPath = this.MapPath("./2003_07_08_DLOTable.rpt");
//string sSrcPath = this.MapPath("./Sample_Report.rpt");
// Generate unique name for output file
StringBuilder sFileName = new StringBuilder(DateTime.Now.ToShortDateString() + "_" +
DateTime.Now.ToShortTimeString() + "_" +
DateTime.Now.Millisecond.ToString());
sFileName.Replace(" ", "_");
sFileName.Replace(":", "_");
sFileName.Replace("/", "_");
string sResultFileName = sFileName.ToString();
string sDesPath = this.MapPath("./CRResult/" + sResultFileName + "_BigFile.pdf");
ReportDocument oRD = new ReportDocument();
oRD.Load(sSrcPath);
dFileDOpts.DiskFileName = sDesPath;
ExportOptions eOpts = new ExportOptions();
eOpts = oRD.ExportOptions;
eOpts.ExportDestinationType = ExportDestinationType.DiskFile;
eOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
eOpts.DestinationOptions = dFileDOpts;
oRD.Export();
oRD.Close();
if (!System.Diagnostics.EventLog.SourceExists("MyApp1 "))
System.Diagnostics.EventLog.CreateEventSource(
"MyApp1", "Application");
EventLog1.Source = "MyApp";
EventLog1.WriteEntry ("Crystal Report pdf export success.");
}
catch(Exception fu)
{
if (!System.Diagnostics.EventLog.SourceExists("MyApp1 "))
System.Diagnostics.EventLog.CreateEventSource(
"MyApp1", "Application");
EventLog1.Source = "MyApp";
EventLog1.WriteEntry ("Something wrong with Crystal Report Load Test!" + fu.Message);
};
---------------- (code end) -------------------------
After running, I got a pdf file in the CRResult folder. So far so good. But
the report was NOT UPDATED to the latest change in the database. So I added one
line to do REfresh:
......
oRD.Load(sSrcPath);
oRD.Refresh(); // This is what I added
......
Well, I got an error on the "oRD.Export()" line after at:
"Query Engine Error on line xxxxx"
So what did I do wrong? Is there any other way to get the refresh view of the
report. And how come the data was not automatically pull form database?
BTW, the report contains simply the content of a database table in a Oracle 9i
Release 2 database. Maybe I don't need to a refresh if I reference to a Stored
Procedure instead of pointing to a database table directly?
Any suggestions are welcomed. Thanks!!
Deecay
|