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.