views:

371

answers:

1

Attempting to keep this short: our shipping personnel use a Windows Mobile-enabled barcode scanner to scan the serial numbers of items shipped on customer orders. That data is submitted via asmx web service and a report is automatically printed to a networked printer showing customer info and the details of items shipped. All of this happens in an intranet environment.

Until recently, I was using the Microsoft Report engine built into Visual Studio (.rdlc files) to generate the reports and the code outlined here to print without user intervention. It worked fine that way for several years.

Recently, I ran up against some report formatting limitations in MS Reports and implemented the reports in Crystal Reports (10.5.3700) instead. The code works fine, but after running in production for a few hours to a day or more, the asp.net worker process is hanging (not sure if this is the appropriate term). The report generating/printing process runs forever without throwing an exception. Recycling the AppPool makes everything work again for a while.

The reports are using "push" mode where the report is given a typed dataset rather than accessing the database itself. To take the CR ReportDocument.PrintToPrinter() method out of the equation, I have considered exporting the generated reports to PDF or similar and then printing the resulting file independently. But I haven't found a great way to do that yet.

Researching the problem, I've read all kinds of complaints about the buggy-ness of Crystal, but I'm hoping that there's is a bug in my code related to cleaning up after the report is printed.

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer
Imports CrystalDecisions.Shared

Public Class CrystalReport

Private _report As ReportDocument

Public Sub New(ByVal Path As String)
    _report = New ReportDocument()
    _report.Load(Path)
End Sub

Public Sub SetDatasource(ByVal DataSet As DataSet)
    _report.SetDataSource(DataSet)
End Sub

Public Sub AddParameter(ByVal Name As String, ByVal Value As Object)

    Dim crParameterFieldDefinitions As ParameterFieldDefinitions = _report.DataDefinition.ParameterFields
    Dim crParameter1 As ParameterFieldDefinition = crParameterFieldDefinitions.Item(Name)
    Dim parameterValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()

    parameterValue.Value = Value
    crParameter1.CurrentValues.Add(parameterValue)
    crParameter1.ApplyCurrentValues(crParameter1.CurrentValues)

End Sub

Public Sub Print(ByVal PrinterPath As String)
    _report.PrintOptions.PrinterName = PrinterPath
    _report.PrintToPrinter(1, True, 0, 0)
    Close()
End Sub

Private Sub Close()
    _report.Close()
    _report.Dispose()
    _report = Nothing
End Sub

End Class

Any ideas for debugging this further? I've never had to resort to real Windows debugging (WinDbg, Process Explorer, etc.), so any recommendation on which debugging tool to try first would be great.

Thank you.

A: 

It sounds like the report actually isn't being released, although by looking at your code you would think you are doing exactly that.

You might try Close()ing and Dispose()ing your report object on the Page_Unload event of your ASP.NET page. This forum post on the Microsoft ASP.NET forums talks about an issue where the maximum amount of report processing jobs is reached, but I imagine the issue could be related.

Heather
This code is being called from an asmx web service rather than an ASP.NET page, so the the Page_Unload suggestion isn't directly applicable in this case. To come close to the Page_Unload idea, I guess I could expose the _report object to the calling code and call Close() and Dispose() from there, but I can't think of any reason why that should work. I will play with the PrintJobLimit registry key to try to see if that's the right general area. Thanks.
Bill
I don't think exposing the object in that case would work either - as you said. I've had to troubleshoot some nasty CR problems before (DLL-hell, mysterious error message numbers that are not documented). Sorry I couldn't be of more assistance. I hope you get it figured out.
Heather
It's just helpful to get another pair of eyes on it -- thanks.
Bill