cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal reports for visual studio 2010 waits for keyboard before printing?

Former Member
0 Kudos

I am using a Crystal Reports report for invoice printing in my application, the problem is that the engine seems to be holding on waiting for a keyboard action, such has pressing the windows key, to either Refresh or Print the document.

PrintDocument doc = new PrintDocument();

// setup printer and page information

ReportDocument rep = new Docs.GtrDefault();

// set database connection information

if (rep.HasSavedData)

     rep.Refresh();               // first place where it hangs, although not always

// set formula fields data

rep.PrintToPrinter(doc.PrinterSettings, doc.DefaultPageSettings, false);          // second place where it hangs

rep.Dispose();

it can hang on either Refresh or PrintToPrinter, usually the former, but all it takes is for me to press the windows key, or some other key combo, for the process to conclude successfully and promptly.

The report has several subreports, could that be causing it?

Any clues on how to solve this?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

Moved to .NET SDK forum

If you:

rep.Refresh();

you are telling it to discard the saved data and therefore it requires you to set the database log on info.

Check your log on routine, likely where it's failing and yes you do have to set the log on info each subreport also:

        //set the crSections object to the current report's sections
        CrystalDecisions.CrystalReports.Engine.Sections crSections = rpt.ReportDefinition.Sections;

        //loop through all the sections to find all the report objects
        foreach (CrystalDecisions.CrystalReports.Engine.Section crSection in crSections)
        {
            crReportObjects = crSection.ReportObjects;
            //loop through all the report objects to find all the subreports
            foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject in crReportObjects)
            {
                if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    //you will need to typecast the reportobject to a subreport
                    //object once you find it
                    crSubreportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)crReportObject;

                    //open the subreport object
                    crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

                    //set the database and tables objects to work with the subreport
                    crDatabase = crSubreportDocument.Database;
                    crTables = crDatabase.Tables;

                    //loop through all the tables in the subreport and
                    //set up the connection info and apply it to the tables
                    foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
                    {
                        crConnectioninfo.ServerName = "VMW2K8CRSE2K8";
                        crConnectioninfo.UserID = "sb";
                        crConnectioninfo.Password = "1Oem2000";
                        crConnectioninfo.DatabaseName = "astellastest";

                        crTableLogOnInfo = crTable.LogOnInfo;
                        crTableLogOnInfo.ConnectionInfo = crConnectioninfo;
                        crTable.ApplyLogOnInfo(crTableLogOnInfo);
                    }
                }
            }
        }

Don

Answers (0)