Skip to Content
0

Crystal Reports - Exchange XML data source programmatically

Jan 11, 2017 at 04:39 PM

116

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Don Williams
Jan 12, 2017 at 04:55 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Jan 11, 2017 at 10:38 PM
0

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

When you export it will refresh the data.

Share
10 |10000 characters needed characters left characters exceeded
Hans-Peter Groh Jan 12, 2017 at 04:45 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded