This is a migrated thread and some comments may be shown as answers.

The data area passed to a system call is too small

1 Answer 695 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Nov 2019, 10:27 AM

I created a report library .dll to print reports ad-hoc with no previewing, so I can use it in a rest api. This has been working fine since installation over 4months ago.

I have just updated to v 13.2.19.1030, now when a report is trying to print is get the following error..

"The data area passed to a system call is too small"

I have copied and pasted my code below..

-------------------------------------------------------------------------------

public void printPalletLabel(string palletBarcode, string courier, string printerName, short copies)
        {
            string reportName = _basePath + "\\Reports\\";

            try
            {
                // CREATE A REPORT INSTANCE FROM THE REPORT FILE
                switch (courier.ToUpper())
                {
                    case "DPD":
                        reportName += "palletLabel_DPD.trdp";
                        break;

                    case "YODEL":
                        reportName += "palletLabel_Yodel.trdp";
                        break;

                    default:
                        reportName += "palletLabel_UKMail.trdp";
                        break;
                }

                // REMOVE URI START IS EXISTS
                if (reportName.StartsWith("file:\\"))
                    reportName = reportName.Substring(6);

                var reportInstance = UnpackageReport(reportName);

                if (reportInstance != null)
                { 
                    // MODIFY CONNECTIONSTRING AND PASS PARAMETER
                    var ds = reportInstance.DataSource;

                    var sqlDataSource = (SqlDataSource)ds;
                    sqlDataSource.ConnectionString = _connectionString;
                    sqlDataSource.ProviderName = "System.Data.SqlClient";
                    sqlDataSource.Parameters["@palletBarcode"].Value = palletBarcode;
                        
                    printReport(reportInstance, printerName, copies);
                }
            }
            catch (Exception ex)
            {
                error = "reporting.printPalletLabel(): " + ex.Message;
            }

            
        }

        private void printReport(Telerik.Reporting.Report report, string printerName, short copies)
        {
            try
            {
                InstanceReportSource reportSource = new InstanceReportSource
                {
                    ReportDocument = report
                };


                // SET PRINTER
                var printerSettings = new System.Drawing.Printing.PrinterSettings
                {
                    PrinterName = printerName,
                    Copies = copies
                };

                // PRINT REPORT
                var reportProcessor = new ReportProcessor();
                reportProcessor.PrintReport(reportSource, printerSettings);
            }
            catch (Exception ex)
            {
                error = "reporting.printReport(): " + ex.Message;
            }
        }
        private Telerik.Reporting.Report UnpackageReport(string reportName)
        {
            var reportPackager = new ReportPackager();

            try
            {
                using (var sourceStream = System.IO.File.OpenRead(reportName))
                {
                    var report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                    return report;
                }
            }
            catch (Exception ex)
            {
                error = "reporting.UnpackageReport(): " + ex.Message;
                return null;
            }
        }

------------------------------------------------------------------------------------

The error occurs at the following line within printReport()

reportProcessor.PrintReport(reportSource, printerSettings); 

 

Any ideas?

 

Thanks 

Andy

 

1 Answer, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 22 Nov 2019, 10:15 AM

SOLVED:

With the help from Milen in technical support this problem has been solved.

Even though the printer, our companies shared network printer, is used every day my myself using MS Word etc, even the Telerik Label Designer, it wouldn't work within my C# application.

I changed to a different printer (PDF creator) and suddenly it started printing!!!

Removed and Re-Installed the driver for the company printer and all started working :-)

Moral of the story is.......Its not always the code, it could be Windows, start afresh especially printer drivers!!!!

Tags
General Discussions
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or