we are getting error "The handle is invalid" when we call the PrintToPrinter function of CryslaReport ReportDocument. This error is not coming always. when we try to print huge numbe rof documents then only we are getting this. CrystalDecisions.CrystalReports.Engine.dll = 13.0.23.2819
at System.Drawing.Printing.StandardPrintController.OnStartPage(PrintDocument document, PrintPageEventArgs e) at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print() at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings) at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings) at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, Boolean reformatReportPageSettings) at Workers.PrintWorker.OnDoWork(DoWorkEventArgs e) in E:\Workers\PrintWorker.cs:line 114
Sometimes we are also getting exception : The remote procedure call failed
StackTrace : at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print() at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings) at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings) at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, Boolean reformatReportPageSettings) at Workers.PrintWorker.OnDoWork(DoWorkEventArgs e) in E:\Workers\PrintWorker.cs:line 114
if (Service.Instance.Processors[_processor].Document != null) //here Document is CrystalReport ReportDocument object
{
using (PrintDocument document = new PrintDocument())
{
PageSettings page = document.PrinterSettings.DefaultPageSettings;
PrinterSettings printer = document.PrinterSettings;
//
printer.Copies = Convert.ToInt16(_destination.ReportRequestHeader.Copies);
printer.PrinterName = _destination.PrinterTypePrinter.Printer.QueueName;
if (printer.PaperSources.Count > 1)
{
PaperSource tray = printer.PaperSources.Cast<PaperSource>()
.Where(s => s.RawKind.Equals(Converter.ToInt32(_destination.PrinterTypePrinter.PaperTray)))
.FirstOrDefault();
if (tray != null) page.PaperSource = tray;
}
//
Service.Instance.Processors[_processor].Document.PrintToPrinter(printer, page, false); //Getting error at this line
}
}
anyone has any idea on these exceptions ? NOTE: this is not always, its coming only when the load is high.