1
votes

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.

4
Well, I took a look again at a simpler report and managed to get it working. What I needed to do was the following: Store the entire report document in the session, not just the data source, don't specify a report type (ActiveX or PDF), and always set the report document in the Page_Load event if there was one in the session. I'll post an update once I manage to get the others working with some code samples.Joel B
try to be precise while asking questions to get a better response from communityTassadaque

4 Answers

1
votes

Its bad idea to store entire report in session if you are receiving lot of user requests.

While working with crystal reports you must reinitialize the report and its login and datasource, parameters etc in each request (post back or no postback does not matter ) before sending out the response. Crystal report does not maintain complete viewstate that is why it should reinitialized each time.

I think you are not reinitializing during postback requests hence the error.

1
votes

Save yourself the headache and DISABLE activeX printing. It blows up your web server with temp files, only works with IE, and is limited to the number of reports you can print at the same time. Set the print mode to Pdf and be done with it. A lot of browsers can print pdfs directly.

crViewer.PrintMode = PrintMode.Pdf;
0
votes

I know this question is old, but I thought I'd chime in just in case someone else has this problem.

I found this page had a number of options for problems that I think are very similar to yours. I was getting the titled 'bobj is undefined' error, but all it really comes down to is that IIS can't find a proper path to the JS files for Crystal.

For myself I ended up placing some folders in my aspnet_client directory in the root of my site (wwwroot) and ensuring that NETWORK_SERVICE had access to the aspnet_client folder. I had to do the same with the 'crystalreportviewers' folder from my x86 SAP folder under

'C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports 20XX\crystalreportviewers'

I also had to add the config from that site into my web.config... and then the viewer started working properly.

Hope it helps!

0
votes

I ran in the similar issue, the report was being generated correctly on the page, but when I try to Zoom, it was saying, "No valid report source is available". To overcome this issue, I simply load the report each time when page is loaded, no matter Postback or normal load.

Also make sure you are properly disposing the Crystal Report Document, otherwise it may start giving "Load Report Failed" error.