I'm having some serious issues trying to get a Crystal Reports report printed from an ASP.Net page. Here is the current setup:
- A Crystal Reports viewer is set up on a page. The report appears fine when viewing the report.
- The report viewer PrintMode is set to ActiveX
- I am setting the report data source from a session variable, as per SAP's recommendation (found in one of their knowledge base articles). The report data source is being set by a call to a WCF service. The data being passed into the report is fine. (Again, the report displays just fine, showing all content like it should).
- The build target for the ASP.Net application and related services are x86.
- Everything is using Crystal Reports version 13, and the ASP.Net web application is using .Net 4. It is being viewed in Internet Explorer 8.
- I've tried checking the ActiveX settings on Internet Explorer 8, and none of them should be a problem (everything is either set to allow or prompt).
- The error happens regardless of running it from the IDE or from a set up website on a separate server.
- The settings for the application pool in IIS on the other server are set to allow 32 bit applications.
When I click on the Print icon on the report viewer, I get the following error message:
"An communication error occurred. Printing will be stopped."
This same error happens more than one machine. If I click OK on the error message the dialog underneath says "Please wait while the Crystal Reports Print Control is loaded.". If I wait, nothing happens. There is no prompt to install an ActiveX control, and nothing pops up allowing me to select a printer (of which I know several are installed).
I've tried doing the following things, none of which have worked:
- Switch the report type to PDF. If I do this, and click the print button on the report viewer I get the following error:
Microsoft JScript runtime error: Object required."
It breaks on this line in particular:
bobj.crv.stateManager.setComponentState('MainContent_reportViewer_UI',eval('('+document.getElementById('_CRYSTALSTATEctl00$MainContent$reportViewer').value+')'));
There are several dynamic images in the report, but all of them are being displayed correctly when viewing the report. They are the only binary objects that I can think of that would be associated with this report. The error is happening in the dynamically created code for the page - not something that I have written.
- I've tried manually installing the ActiveX control from the correct .cab file. This made no difference in any of the scenarios.
- I've installed the latest Crystal Reports service pack (service pack 3). Again, this didn't change anything.
- I've tried setting up a Virtual Directory for the CrystalReportViewers13 inside the Default Web Site, as recommended by some forum posts I came across. This also has had no effect.
- Enabling ViewState on the page has no effect on whether printing works or not.
- I've tried adding my own print button and a drop down list with a list of available printers. When I click my own custom print button and call PrintToPrinter(), I get the same error message as trying to print a PDF report:
"Microsoft JScript runtime error: Object required"
...and it breaks on the same line as when trying to print a PDF report when clicking the Print button.
I've been beating my head against this for at least a day now, and I'm fresh out of ideas. Anyone have any idea what might be causing this?
EDIT:
Well, here's what I did in order to get things to work. It ended up being a lot simpler of a fix than what I was thinking:
Stuff the entire ReportDocument into the session. Your page load should look something like this:
protected void Page_Load(object sender, EventArgs e) { if (Session["report"] != null) { reportViewer.ReportSource = Session["report"]; } BuildReport(); }
Keep the ReportViewer as simple as possible - don't specify the report type (PDF or ActiveX). Setting it to anything seemed to result in problems. This is what it looks like in the page source:
... and that was it. I can't believe I spent about a day trying to get it to work when it ended up being so simple. Hopefully this post helps anyone else facing the same problem.