Skip to main content
All docs
V24.1

DefaultWebDocumentViewerContainer.UseDbStorage(String) Method

Enables the database storage for documents and reports.

Namespace: DevExpress.XtraReports.Web.WebDocumentViewer

Assembly: DevExpress.XtraReports.v24.1.Web.dll

NuGet Package: DevExpress.Web.Reporting.Common

Declaration

public static void UseDbStorage(
    string connectionString
)

Parameters

Name Type Description
connectionString String

Specifies a connection string for the database where documents and reports are stored.

Remarks

Overview

To preview a report, the Web Document Viewer generates a report document. For more information about the role the document plays in Document Viewer operations, review the following help topic: Document Viewer Lifecycle.

The generated documents are stored in the memory cache unless the developer explicitly specifies another cache type at application startup. Cache memory is part of the application pool, and it is an unreliable method that cannot store reporting documents for the application lifetime. The application pool is recycled on many occasions, such as when memory usage reaches a certain limit, when an idle session is closed, or during a scheduled cache cleanup. When the application pool is disposed of, the memory cache flushes, the document is deleted, and the document viewer can no longer display that document. The same scenario applies to the exported document and to the report document that the Report Designer generates in Preview.

If you run multiple instances of an application, use the cache supported by the database repository to prevent cache data loss. Such a cache is available for all report documents and exported documents.

For more information, review the following help topic: Web Document Viewer Cache Management.

Implementation

To enable database caching, do the following:

  1. Obtain a database connection string for the existing database.
  2. Initialize the database tables and schema using the IStorageDbInitializer interface.
  3. Call the UseDbStorage method at application startup.

The following code snippet enables database caching for the XpoStorageConnection connection string:

DevExpress.XtraReports.Web.WebDocumentViewer.DefaultWebDocumentViewerContainer.UseDbStorage(System.Configuration.ConfigurationManager.ConnectionStrings["XpoStorageConnection"].ConnectionString);

Use IStorageDbInitializer Interface for Database Initialization

The IStorageDbInitializer interface is utilized to initialize the database used for database caching. It is intended for situations when an application runs under a user account without administrator rights.

For security reasons, you can deny access to the system tables and prohibit modification of the database schema for the database account used in the end-user application. In this case, you can use the IStorageDbInitializer interface to update the database schema under administrator credentials:

//...
DevExpress.XtraReports.Web.WebDocumentViewer.DefaultWebDocumentViewerContainer.UseDbStorage(System.Configuration.ConfigurationManager.ConnectionStrings["XpoStorageConnection"].ConnectionString);
ASPxWebDocumentViewer.StaticInitialize();
((IStorageDbInitializer)DevExpress.XtraReports.Web.WebDocumentViewer.DefaultWebDocumentViewerContainer.Current.GetService(typeof(IStorageDbInitializer))).InitDbSchema();
//...
See Also