Hi,
I am writing a program that will export a report using a XML data source. I have designed a simple one table report to demonstrate this feature. Unfortunately, I cannot seem to figure out how to feed an updated XML file to the report at run-time. The following is a code snippet showing what I am trying to do.
// open the report file
ReportDocument rd = new ReportDocument();
rd.Load(@"Report1.rpt");
// read the xml data
DataSet reportData = new DataSet();
reportData.ReadXml(@"Report1.xml");
// update the report with the new data
rd.Database.Tables[0].SetDataSource(reportData.Tables[0]);
// export the report
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "Report1.pdf";
CrExportOptions = rd.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
rd.Export();
System.Console.WriteLine("file exported");
The following exception is raised when execution reaches the Export() function.
CrystalDecisions.CrystalReports.Engine.DataSourceException was unhandled
HResult=-2147215616
Message=Failed to load database information.
Error in File Report1 {A9470C9B-2CDE-458C-831C-35B3FC75F2BC}.rpt:
Failed to load database information.
Source=CrystalDecisions.ReportAppServer.DataSetConversion
StackTrace:
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
at CrystalApp.Program.Main(String[] args) in c:\CrystalApp\Program.cs:line 39
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
HResult=-2147482931
Message=Failed to load database information.
Error in File Report1 {A9470C9B-2CDE-458C-831C-35B3FC75F2BC}.rpt:
Failed to load database information.
Source=""
ErrorCode=-2147482931
StackTrace:
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
InnerException:
Any insight on this error would be greatly appreciated.
Thx.