Slow printing of crystal reports from a c# winform RRS feed

  • Question

  • I'm am sometimes having a problem with printing crystal reports from a c# winform. I was wondering why that would be. 

    Below is the code being called when a crystal report is printed:

      public static void PrintCrystalReport(string reportPath, List<KeyValuePair<string, string>> lstParameters, List<PageColorOptions> colorOptions, DataSet ds = null, int numberOfCopies = 1)
                var main = Application.OpenForms.OfType<Main>().SingleOrDefault();
                bool showPrintDialogBox = main.ShowPrintDialogBox();
                if (Main.computerId == -1 && !showPrintDialogBox)
                    MessageBox.Show("Please create printers associated to this computer.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ReportDocument rpt = new ReportDocument();
                    //  reportPath =  Path.Combine(@"..\..\", reportPath);
                    if (ds != null) rpt.SetDataSource(ds);
                    foreach (KeyValuePair<string, string> p in lstParameters)
                        rpt.SetParameterValue(p.Key, p.Value);

                    CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
                    crConnectionInfo.ServerName = ConfigurationManager.AppSettings["SQLServerServer"];
                    crConnectionInfo.DatabaseName = "Mandtob_QA";// ConfigurationManager.AppSettings["SQLServerDatabaseName"];
                    crConnectionInfo.UserID = ConfigurationManager.AppSettings["SQLServerUserName"];
                    crConnectionInfo.Password = ConfigurationManager.AppSettings["SQLServerPwd"];
                    var connectionAttributes = new DbConnectionAttributes();
                    connectionAttributes.Collection.Set("Provider", "SQLOLEDB"); //eg: SQLOLEDB
                    crConnectionInfo.Attributes.Collection.Add(new NameValuePair2 { Name = "QE_LogonProperties", Value = connectionAttributes });
                    CrystalDecisions.CrystalReports.Engine.Database crDatabase = rpt.Database;
                    CrystalDecisions.CrystalReports.Engine.Tables crTables = crDatabase.Tables;
                    TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
                    foreach (Table t in crTables)

                        crTableLogOnInfo = t.LogOnInfo;

                        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;

                    if (showPrintDialogBox)
                        PrinterSettings printerSettings = new PrinterSettings();
                        PrintDialog printDialog = new PrintDialog();
                        printDialog.PrinterSettings = printerSettings;
                        printDialog.AllowPrintToFile = false;
                        printDialog.AllowSomePages = true;
                        printDialog.UseEXDialog = true;

                        DialogResult result = printDialog.ShowDialog();

                        if (result == DialogResult.Cancel)

                        rpt.PrintOptions.PrinterName = printerSettings.PrinterName;
                        rpt.PrintToPrinter(printerSettings.Copies, false, 0, 0);

    Debra has a question

    • Moved by Stanly Fan Monday, April 16, 2018 6:56 AM
    Thursday, April 12, 2018 2:37 PM

All replies

  • Hi Debra,

    According to your description, your issue is more related about Crystal Reports. it will be more appropriate to ask your question at Crystal Reports Forum.

    Thank you for your understanding.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 13, 2018 5:46 AM