Improving Crystal Reports Performance in Visual Studio .NET Applications
Improving Crystal Reports Performance in Visual Studio .NET Applications
Improving Crystal Reports Performance in Visual Studio .NET Applications
NET Applications
Applies to:
Crystal Reports 9.1 to Crystal Reports 2008 (12.0.x) when used in applicable versions of Visual Studio .NET. For more information, visit the Business Objects homepage.
Summary
This article discusses techniques, tips and best practices that should lead to improved report performance in Visual Studio .NET applications using the Crystal Reports SDK for Visual Studio .NET. Author: Ludek Uher
Author Bio
Ludek Uher is a Senior Engineer with Technical Customer Assurance, SAP Business Objects. He specializes in the SDKs supplied with Crystal Reports and BusinessObjects Enterprise.
Table of Contents
Expected Performance .......................................................................................................................................3 Comparison of Report Performance in the Crystal Reports Designer and Custom Application ........................3 Using Progress Bar to Monitor Report Progress ................................................................................................4 Troubleshooting Slow Performance ...................................................................................................................4 Performance Impact is on Report Load..............................................................................................................5 Report Design Issues......................................................................................................................................5 Report Options ................................................................................................................................................6 Old or Incorrect Runtime .................................................................................................................................6 Performance Impact is on Database Connection / Data Retrieval .....................................................................7 ADO .NET Dataset..........................................................................................................................................7 Coding Issues .....................................................................................................................................................9 Performance Issues when Printing.....................................................................................................................9 Other Tips and Tricks when Using the Crystal Reports .NET SDK..................................................................10 Using Sessions .............................................................................................................................................10 Too Many Reports Being Processed by the Report Engine .........................................................................10 Related Content................................................................................................................................................11 Copyright...........................................................................................................................................................12
Expected Performance
An application will only be as fast as the reports it uses. A large part of tuning an application for scalability is ensuring that all the reports are designed in a way such that they will perform at an optimum speed. Report size is one of the obvious factors in report performance. When designing for scalability, consider using smaller reports. Also, reports designed for desktop applications may not be appropriate for web-based applications. Typically, the load of the first report in an application will be slower than all subsequent report loads. Depending on the complexity of the report, the time to load the first report may be as much as 20 to 30 seconds or longer. Sometimes, report load time will be significantly longer. This is a normal and expected behavior as a number of Crystal Reports assemblies, com files etc., have to be loaded and initialized before a report can be processed. Once these have been loaded, they are reused and thus the performance improves on subsequent report loads. The only way to improve the end user experience on first report load is to offset the initial load time on application load or some other part of the application where the performance hit is acceptable.
Comparison of Report Performance in the Crystal Reports Designer and Custom Application
It is always useful to compare the performance of a report running in an application to performance in the Crystal Reports designer. Slow report performance in the CR designer will usually not improve when that same report is ran from a custom application. Typically, the opposite will be the case. This is because setting of a database connection in the CR designer happens immediately on report load when it prompts for the database logon parameters. At runtime, the logon method for the tables doesn't make the connection right away. Rather it happens on the call to the view / print to printer / export method. Thus these comparisons need to be done with consideration.
Temporarily inserting the following code into your project may help to determine the slow down points: private void button_View_Click(object sender, System.EventArgs e) { System.DateTime startTime, endTime; System.TimeSpan diffTime; if(crReportDocument != null) { crReportDocument.Close(); crReportDocument.Dispose(); crReportDocument = null; } // reseting the display text back to zeros this.textBox_Start.Text = "0"; this.textBox_End.Text = "0"; this.textBox_Diff.Text = "0"; // instantiate a new ReportDocument object crReportDocument = new ReportDocument(); // mark the time before we Load the report from disk startTime = System.DateTime.Now; this.textBox_Start.Text = startTime.TimeOfDay.ToString(); if (this.textBox_Filename.Text.Length<1) return; crReportDocument.Load(this.textBox_Filename.Text, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault); // mark the time after the report was successfully loaded endTime = System.DateTime.Now; this.textBox_End.Text = endTime.TimeOfDay.ToString();
// calculate the time difference, and display the time in TotalMilliseconds diffTime = endTime.Subtract(startTime); this.textBox_Diff.Text = diffTime.TotalMilliseconds.ToString(); }
Report Options The Verify on First Refresh option (File > Report Options) forces the report to verify that no structural changes were made to the database. There may be instance when this is necessary, but once again, the option should be used only if really needed. Often, disabling this option will improve report performance significantly. The Verify Stored Procedure on First Refresh option (File > Report Options) is essentially the same function as above. However, this option will only verify stored procedures.
Old or Incorrect Runtime If at all possible, use the latest runtime, be it with a custom application or the Crystal Reports Designer. The latest updates for the current versions of Crystal reports can be located on the SAP support download page. Incorrect Crystal Report version will cause incompatibility with Microsoft Visual Studio .NET. For details of which version of Crystal Reports is supported in which version of VS .NET, please refer to the Crystal Reports assembly versions and Visual Studio .NET Wiki. For the correct Crystal Reports runtime files please refer to the Crystal Reports for Visual Studio .NET Runtime Distribution Wiki.
thus reduce the number of queries to the database. The C# code listing below illustrates how this could be accomplished.
DataSet ds; // use the filename of the report as the cache lookup key string datasetCacheKey = report.FilePath; if (Cache[datasetCacheKey] != null) { ds = (DataSet) Cache[datasetCacheKey]; } else { ds = new DataSet(); // perform query and fill dataset ... // insert the dataset into the cache Cache.Insert(datasetCacheKey, ds); } // set the dataset as the data source for the first table in the report report.Database.Tables[0].SetDataSource(ds);
The first access to the above page will not be any faster than without using caching, but on subsequent returns to the page will result in performance increase. Table linking and number of records in the dataset also impact report performance. Table linking Crystal Reports does not use the table links or keys defined in the ADO .NET. The report will use the table linking defined in the report and will link the tables internally when the report is processed. Indexes are not used by the ADO .NET (XML) driver. This process will load the entire ADO .NET dataset into memory, which results in slower performance. Reports that are intended to use ADO .NET datasets should be built off of single tables, stored procedures or command tables. Ensure the number of records returned is reasonable Obviously the more records, the slower the report generation. However due to the table linking limitation and the need to create and use a copy of the dataset, the number of records used in a dataset becomes critical. Datasets of tens of thousands of records will take an inordinate amount of time to process, sometimes even leading to report or application failure. DontVerifyAttachedRecordset This is an option set in the registry. The option is equivalent to Verify on First Refresh and Verify Stored Procedure on First Refresh options. By default, the option is set to No. Setting this option to Yes stops the Crystal Reports engine from verifying the ADO .NET dataset and this may improve performance. Note that explicitly not verifying the dataset may lead to malfunctioning report if the structure of the dataset is changed from what the report was designed with. For Crystal Reports 2008 look for this option in the registry at: HKEY_CURRENT_USER\Software\Business Objects\Suite 12.0\Crystal Reports\DatabaseOptions For more information regarding Crystal reports and ADO .NET datasets, see the following articles: Crystal Reports Guide To ADO.NET Reporting Off ADO.NET Datasets
Coding Issues
Code will affect performance. It is recommended that before using the Crystal Reports SDK, the developer is familiar with the Crystal Reports developer help files. Examples of inefficient code leading to slow performance include incorrect database logon, incorrect printer code, incorrect export code, unhandled report objects, and more. Code issues are beyond the scope of this article. However, becoming familiar with the Crystal Reports Developer Library should be a first step. Also, see the following resources: Crystal Reports For Visual Studio 2005 Walkthroughs Advanced use of Crystal Reports for Visual Studio .NETs feature set and object model
Other Tips and Tricks when Using the Crystal Reports .NET SDK
Using Sessions If a report is used in a web application, when paging through the report, printing or exporting, the default behavior of the Crystal Reports print engine is to page through a report rerunning the report on each button click. Depending on the report design this may visibly affect report performance. To resolve this issue, place the report object into session and view, page, or print/export the session object from the viewer. The following code explains the use of a Crystal report in a session:
Dim _ReportDocument As ReportDocument If Not Me.IsPostBack or Session("Report") = Nothing Then _ReportDocument = New ReportDocument Dim _dtAttendanceDate As DateTime _dtAttendanceDate = CDate(AttendanceYear & "-" & AttendanceMonth & "-01") _ReportDocument.Load(sGlobalPath & "\Report_Attendance31.rpt") Dim _Ds As New DataSet _Ds = LoadDataset() For iCount As Integer = 0 To _ReportDocument.Database.Tables.Count - 1 _ReportDocument.Database.Tables(iCount).SetDataSource(_Ds) Next Session.Add("Report", _ReportDocument) Else _ReportDocument = CType(Session("Report"), ReportDocument) End If Me.CrystalReportViewer1.ReportSource = _ReportDocument
Too Many Reports Being Processed by the Report Engine The Crystal Reports engine is limited to processing 75 print jobs by default. Note that one Print Job is not equal to one report. Nor is a Print Job equal to a Processor license. A report with a single subreport in the report header will, at minimum take two print jobs to run. Actions such as paging, drilling to a section or group, text searches, etc. are considered to be individual Print Jobs. It does affect the performance. More users and more subreports in a repeating section will require more jobs to run the report. This will affect performance of the report engine and may even lead to server crashes. The number of Print Jobs the engine is allowed to process can be increased by modifying the PrintJobLimit registry entry. For Crystal Reports 2008, the registry key is here: HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 12.0\Report Application server\InprocServer Changing the PrintJobLimit will impact the hardware behavior and may adversely impact the functioning of the server. If raising the PrintJobLimit does not resolve the performance issue, then other solutions need to be considered. These include: more memory/CPU Web farm/Web garden See the article Crystal Reports 10 for .NET Feature Overview, p. 10 for more details. Also, please refer to the Microsoft article How Do I Use Crystal Reports in a Web Farm or Web Garden?. high-end products such as the Crystal Reports Server or Business Objects Enterprise.
For more information on choosing the correct SDK, see the following: Choosing the Right Business Objects SDK for Your Needs Choose the Right SDK for the Right Task
Related Content
The following SAP BusinessObjects notes contain further information: Passing multiple condition If-Then-Else date range to an SQL statement Slow performance when previewing reports in CR 10 .NET application Crystal Reports XI .NET application loads data slowly Slow performance when using ADO .NET dataset in .NET application Delay when changing data source connection in CR 10 .NET application Report loads slowly in .NET application when development computer not accessible Additionally, please refer to the following Articles: Optimizing Reports for the Web Crystal Reports 2008 Component Engine Scalability Interactivity and Reports in Web Applications How Printer Driver Options Affect a Report
Copyright
Copyright 2009 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.