Share via


Binding to a Cached Embedded Report Class

Object Model

This report binding scenario uses ReportDocument (see Report Binding with ReportDocument Object Model.)

Location of Reports

Reports are embedded into the project.

Description

When a report is embedded into a Visual Studio project, a report wrapper class that represents the report file in the project is automatically generated. At the same time, a cache management utility class for that report is also automatically generated.

Use of the wrapper class is described in Binding to an Embedded Report Class.

In this scenario, you bind the CrystalReportViewer control to the cache management utility class, so that report caching into the ASP.NET Cache object is handled automatically.

Note

For detailed information on caching reports and the cache management utility class, see Should I Use Regular or Cached Reports?.

Use of caching

Caching has a limited and specific use, which can overuse system resources if not carefully managed. To learn when to use caching, see Cache Reports with "High Shareability".

Caching non-embedded reports

If you want to manage the caching of non-embedded reports, you must create your own cache management utility class. For more information, see Binding to a Non-embedded Report Loaded into a Cache Management Utility Class.

Pros

  • Made for shareability: ideal for storing reports that have high shareability and few permutations in parameters or logon information.
  • Optimizes data access: if reports with high shareability are very large, or have a query that is so complex that it takes several minutes to retrieve, the data is accessed more quickly with the cache management utility class.

Cons

  • Server taxing: reports that remain in the ASP.NET Cache object can burden memory resources on the server.
  • Persistence issues: cache has certain dependencies that allow it to check for changes in a report instance and recache the report instance. However, if the database changes, the report instance in the Cache does not refresh to show that change.
  • Consumes resources: a report with parameters that are called frequently with different parameter strings (especially if one of those parameters is the user id) mean a new cached report each time. This consumes system resources. If the report is not highly shared, the report instance should instead be assigned to a Session object. See Session and Persistence of the ReportDocument Object Model.

To bind to a cache management utility class

Note

This procedure works only with a project that has been created from Project Setup. Project Setup contains specific namespace references and code configuration that is required for this procedure, and you will be unable to complete the procedure without that configuration. Therefore, before you begin this procedure, you must first follow the steps in Project Setup.

  1. Within the ConfigureCrystalReports() method (that you created in Project Setup), delete the existing lines of code to replace the report wrapper class with the cache management utility class.

  2. Instantiate the cache management utility class that is associated with the Hierarchical Grouping.rpt.

``` vb
Dim cachedHierarchicalGroupingReport As CachedHierarchical_Grouping
= New CachedHierarchical_Grouping()
```

``` csharp
CachedHierarchical_Grouping cachedHierarchicalGroupingReport = new
CachedHierarchical_Grouping();
```
  1. Pass the cache management utility instance to the CrystalReportViewer control.
``` vb
myCrystalReportViewer.ReportSource = cachedHierarchicalGroupingReport
```

``` csharp
crystalReportViewer.ReportSource = cachedHierarchicalGroupingReport;
```
  1. To view the report, build and run your project.

See Also