Hi all, I have a piece of code in my C# console application to export from
crystal report files to PDF. For some reports files, I get errors below. I
have Crystal Reports 8.5 with service pack installed on my local machine.
What is the reason to cause this "Unknown Query Engine Error"? This is a
report with 3 sub-reports, is there anything missing in my code to handle
this type of reports?
Thanks a lot!
=====================Error Call Stack Begins============================
Error Message: Unknown Query Engine Error
Error Source: CrystalDecisions.CrystalReports.Engine
Error Stack Trace: at .F(String , EngineExceptionErrorID )
at .A(Int16 , Int32 )
at .@(Int16 )
at
CrystalDecisions.CrystalReports.Engine.FormatEngin e.Export(ExportRequestContext
reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngin e.Export()
at CrystalDecisions.CrystalReports.Engine.ReportDocum ent.Export()
at MyApp.MyClass.CrystalReportsNet.exportReport(Strin g reportPath, String
reportNameCode, DateTime startDate, DateTime endDate, Int32 saveOrPrint,
ReportDocument rd) in c:\work\crystalreportsnet.cs:line 258
Error TargetSite: Void F(System.String,
CrystalDecisions.CrystalReports.Engine.EngineExcep tionErrorID)
ErrorID: DataSourceError
HelpLink: NULL
=======================Souce Code Begins Here========================
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
.......
ReportDocument rd = new ReportDocument();
rd.Load(@"c:\temp\a.rpt");
ParameterFieldDefinitions crParams = rd.DataDefinition.ParameterFields;
foreach (ParameterFieldDefinition def in crParams) {
if (def.IsLinked()) {
continue;
}
string paramName = def.ParameterFieldName;
// create new Parameter Discrete Value object
ParameterDiscreteValue paramValue = new ParameterDiscreteValue();
// Set value of Discrete value object
switch (paramName.ToUpper()) {
case "@DEALERID":
paramValue.Value = dealerID;
break;
case "@LANGUAGEID":
paramValue.Value = languageID;
break;
case "@REPORTTYPE":
paramValue.Value = MPAReportType;
break;
case "@RPTMONTH":
paramValue.Value = month;
break;
case "@RPTYEAR":
paramValue.Value = year;
break;
case "@CURRENTMONTH":
paramValue.Value = month;
break;
case "@CURRENTYEAR":
paramValue.Value = year;
break;
}
// extract collection of current values
ParameterValues currentValues = def.CurrentValues;
// Add Discrete value object to collection of current values
currentValues.Add(paramValue);
// apply modified current values to param collection
def.ApplyCurrentValues(currentValues);
}
foreach (Section sec in rd.ReportDefinition.Sections) {
foreach (ReportObject report in sec.ReportObjects) {
if (report.Kind == ReportObjectKind.SubreportObject) {
SubreportObject subreport = (SubreportObject)report;
ReportDocument subRepDoc =
subreport.OpenSubreport(subreport.SubreportName);
foreach (Table tbl in subRepDoc.Database.Tables) {
TableLogOnInfo tliCurrent = tbl.LogOnInfo;
tliCurrent.ConnectionInfo.ServerName = "MyODBC";
tliCurrent.ConnectionInfo.DatabaseName = "MyDatabase";
tliCurrent.ConnectionInfo.UserID = "MyUsername";
tliCurrent.ConnectionInfo.Password = "MyPassword";
tbl.ApplyLogOnInfo(tliCurrent);
}
}
}
}
foreach (Table tbl in rd.Database.Tables) {
TableLogOnInfo tliCurrent = tbl.LogOnInfo;
tliCurrent.ConnectionInfo.ServerName = "MyODBC";
tliCurrent.ConnectionInfo.DatabaseName = "MyDatabase";
tliCurrent.ConnectionInfo.UserID = "MyUsername";
tliCurrent.ConnectionInfo.Password = "MyPassword";
tbl.ApplyLogOnInfo(tliCurrent);
}
try {
DiskFileDestinationOptions save = new DiskFileDestinationOptions();
save.DiskFileName = @"c:\temp\a.pdf";
ExportOptions exp = new ExportOptions();
exp = rd.ExportOptions;
exp.ExportDestinationType = ExportDestinationType.DiskFile;
exp.ExportFormatType = ExportFormatType.PortableDocFormat;
exp.DestinationOptions = save;
rd.Export();
return true;
} catch {
//.......
}
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy