Skip to Content
Former Member
Mar 10, 2009 at 06:06 PM

Sporadic Get Last Page Number Error?


I am using VB 2008 and Visual Studio 2008 I use the version of CR that comes with VS 2008. I have created an application which prints reports. The application works 97% of the time with no issue. Occasionally, I will get the following error:

Error Message: The Report Application Server failed


Source: RptControllers.dll

Target (Method): Int32 GetLastPageNumber(CrystalDecisions.ReportAppServer.ReportDefModel.RequestContext)

Stack Trace: at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.GetLastPageNumber(RequestContext pRequestContext)

at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext)

at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)

at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)

at Workflow_WPF.ReportPrinting.PrintPrimaryRLRecordCopy(objVisitData w)

My source code is:

Dim PrimaryRL As New rptReferralLetter


If DetermineIfPrinterHasError(My.Application.PrinterSettings.ActivePlainPrinter) = False Then


PrimaryRL.PrintOptions.PrinterName = My.Application.PrinterSettings.ActivePlainPrinter

PrimaryRL.PrintOptions.CustomPaperSource = My.Application.PrinterSettings.ReturnPaperSource(My.Application.PrinterSettings.ActivePlainPrinter, My.Application.PrinterSettings.ActivePlainTray)

PrimaryRL.PrintToPrinter(1, False, 1, 100)




MessageBox.Show("The printer reports that there is an error. You must correct this error before you can print. The reported message is: " & vbCrLf & vbCrLf & PrinterErrorString, My.Application.GlobalSettings.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information)

End If

Catch ex As Exception

MessageBox.Show("There was an error printing the record copy of the referral letter. It may need to be reprinted.", My.Application.GlobalSettings.ApplicationName, MessageBoxButton.OK)

End Try


PrimaryRL = Nothing


When the user simply clicks to print again, it works just fine. I cannot replicate the error and do not know how to prevent this from happening. This is always the third report printed in a row. The first is another similar page with identical code. The second is an envelope. The third is this page with this code. The error localizes the problem to this particular procedure.

I use 100 as the last page in code since I cannot predict the length of the report. It is usually 1-2 pages.