cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports - Exchange XML data source programmatically

Former Member
0 Kudos

Hi,

I designed a report pointing to local XML and XSD files. Now, I want to process the .rpt file programmatically in a .NET 4.6.2 app by specifying a new XML data source. However, after I call SetDataSource and Refresh on the ReportDocument, the report object throws a CrystalDecisions.CrystalReports.Enging.DataSourceException when I call ExportToStream:

{"Fehler beim Laden der Datenbankinformationen.\rFehler in der Datei ExternalXMLReport 1856_6320_{0543C9E8-7559-44A9-BADE-1551F0E603BE}.rpt:\nFehler beim Laden der Datenbankinformationen"}

The corresponding code snippet looks like this:

var report = new ReportDocument();
report.Load("ExternalXMLReport.rpt");
DataSet reportData = new DataSet();
reportData.ReadXml("catalog.xml");
report.SetDataSource(reportData);
report.Refresh();
var pdfStream = report.ExportToStream(ExportFormatType.PortableDocFormat);


How can I avoid this exception?

The goal is to design reports with XML and XSD files locally with the Crystal Reports Designer Desktop Application and passing the latest data to the report at runtime.

I also tried setting the XSD file on the DataSet with no success.

Thanks for your help in advance.

Best Regards,

HP

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi HP,

Search for KBA 2281780 and download the Parameter Test app, it has the ability to set location to XML data sources and see if that works for you.

Your code is actually loading the XML into a Dataset and you are setting the Reports data source to the DS. You don't need to do that when using XML:

try
{
foreach (CrystalDecisions.CrystalReports.Engine.Table rptTable in rpt.Database.Tables)
{
tLogonInfo = rptTable.LogOnInfo;
tLogonInfo.ConnectionInfo.ServerName = btrDataFile.Text; // Folder where XML file resides
tLogonInfo.ConnectionInfo.DatabaseName = btrSearchPath.Text; // My.xml
//tLogonInfo.ConnectionInfo.UserID = "";
//tLogonInfo.ConnectionInfo.Password = "";
tLogonInfo.TableName = rptTable.Name;

try
{
rptTable.ApplyLogOnInfo(tLogonInfo);
}
catch (Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}

Now export the report.

Don

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Don,

unfortunately, also without Report.Refresh() I get...

Fehler beim Laden der Datenbankinformationen.
Fehler in der Datei ExternalXMLReport1-3 12128_1004_{5BEAC23C-1BB6-42A9-B4A8-72D5BA8245C4}.rpt:
Fehler beim Laden der Datenbankinformationen

Regards,
HP

0 Kudos

Don't call Report.Refresh(), it's using the old data connection info.

When you export it will refresh the data.