From: Hardy Wang on
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.FormatEngine.Export(ExportRequestContext
reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
at MyApp.MyClass.CrystalReportsNet.exportReport(String 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.EngineExceptionErrorID)
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


From: "TerryFei" on
Hi Hardy,

The Crystal Report is a third-party software integrated with the VS.NET
IDE, and it is not supported by Microsoft, please refer to the following KB
article for the information on the licensing and support on Crystal Report:
INFO: Licensing and Support for Crystal Reports for Visual Studio .NET
http://support.microsoft.com/?id=317789

If you have more concern on this issue, I suggest you contact crystal
report support for help:
http://support.businessobjects.com/

And the following is the Forum where you will receive some specific helps:
http://support.businessobjects.com/forums/content.asp?fid=2-5-1&sk=5&

Thanks for your understanding!
Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)