Share via


Session and Persistence of the ReportDocument Object Model

What is Session?

Session is a Web server-based approach used in both ASP and ASP.NET for preserving state. Session allows you to persist any object for the entire length of a user's session by storing that object in the Web server's memory.

Session is typically used to do either of these things:

  • Store information that needs to persist its state during the entire length of a user session, such as logon or other information required as users navigate the Web application.
  • Store an object that needs to persist its state only across a page reload or a functionally grouped set of pages.

The strength of Session is that it preserves the user's state information on the Web server for access at any time from any page. Since the browser doesn't have to store any of this information, any browser can be used, even browser devices such as PDAs or cell phones.

Limitations of this persistence approach

  • The amount of server memory required by Session grows as more users log on.
  • Each user who accesses the Web application generates a separate Session object. Each Session object lasts for the length of the user's visit plus an inactivity period.
  • If many objects are persisted into each Session, and many users are using the Web application simultaneously (creating many Sessions), the amount of server memory devoted to Session persistence can become significant, limiting scalability.

For alternate persistence approaches see the following:

Persisting the ReportDocument object model with Session

If the report has been encapsulated within the ReportDocument object model, the ReportDocument object model must be persisted using a server-based approach such as Session or Cache.

To persist a report within the ReportDocument object model using Session, instantiate the ReportDocument and then assign it to Session.

Note

For a complete example, see the tutorial Tutorial: Persisting the ReportDocument Object Model Using Session.

Session is the simplest approach and is preferred when you are learning to build an ASP.NET Web application using Crystal Reports. It is also the recommended approach for storing ReportDocument instances where the report has low shareability. For an explanation of shareability, see Cache Reports with "High Shareability".

Limitations of persisting the ReportDocument object model with Session

Whenever a ReportDocument instance has a high degree of shareability, consider using Cache instead of Session.

Contrasting Session and ViewState

Session is primarily concerned with persisting the state of objects in the code-behind class. ViewState is primarily concerned with persisting the state of controls on the Web page. When a control on the Web page is bound to an object in the code-behind class and both need to be persisted across page reloads, Session and ViewState share the roles of persistence.

In this case ViewState persists a CrystalReportViewer control, and Session persists a ReportDocument object that is bound to the control.

Tutorials

For a thorough understanding of persisting reports, you can work through the following tutorial.