Hi,
I have developed a .NET Windows Forms application to generate and print the reports as per the business requirements. The reports were designed using Crystal Reports 8.5 and XI R2 versions. Our Client has been using these reports for a long period. There is a legacy system which generates these reports and it is developed using VBScript, Crystal Reports (ActiveX) components. The legacy system works for Windows 32-bit machines only. Now I have developed a .NET solution to replace the legacy system for Windows 64-bit machines. The .NET application is developed using C# and Crystal Reports .NET Framework. I have downloaded CRforVS_redist_install_32bit_13_0_14.zip file from SAP website, installed it on DEV machine and referenced the assemblies (.DLLs installed) in .NET application. The data source for Crystal Reports are XML files and we need an XML Data Driver. So I have downloaded the CRforVS_crdbxml_13_0_14.zip file from SAP website and installed it as per the instructions given. When tested the .NET application, it works fine for some of the reports. I mean, the application generates the Crystal Reports out of .rpt files and prints them. However, the application fails for some of the reports and gives the error below.
Failed to open the connection.
PRSales 4408_5568_{7A85C4FB-D0E4-462A-BEDC-BD42D4DD4981}.rpt
When I verified the same report thru the legacy system, it is able to generate and print the report without any issues. The data source for this report (.rpt) is an XML file residing on the local machine. The XML file path is mentioned in the .rpt file. I have opened the .rpt file thru Crystal Reports designer and able to give a sample print. However, the .NET application is unable to generate a report out of .rpt file and print it. The issue does not occur for all the .rpt files; some of them are generated and printed while the others give the errors. Here below is the code written in .NET application to generate and print the reports out of .rpt files.
Private void PrintCrystalReports()
{
try
{
// Create instance for Crystal Report document
ReportDocument reportDoc = new ReportDocument();
// Prepare the Crystal Report file path and load it into the Crystal Report document created
string strReportPath = string.Format("{0}{1}", strCRXMLTemplatesPath, strReportFileName);
reportDoc.Load(strReportPath, OpenReportMethod.OpenReportByDefault);
// Set the printer settings to print the Crystal Report
PrinterSettings printerSettings = new PrinterSettings() { Duplex = Duplex.Simplex };
PageSettings pagesetting = new PageSettings();
PrintLayoutSettings printlayout = new PrintLayoutSettings();
// Send the Crystal Report to printer
reportDoc.PrintToPrinter(printerSettings, pagesetting, false);
// Close the Crystal Report document
reportDoc.Close();
}
catch
{
// Exception handling code
}
}
Please let me know if anything wrong in the code snippet above or I have to add any extra code to make it working. Thanks in advance.