Report Snapshots and rsReportNotReady

Two very useful features of Reporting Services (version 2000 and above) are snapshot execution and report history. Snapshot execution allows you to cache the report execution. Optionally, you can keep the cached reports in history, e.g. if the user wants to keep a copy of the report for historical analysis.

Once a report is enabled for snapshot execution, you can generate the history snapshot by invoking the CreateReportHistorySnapshot API assuming you need to do so programmatically, e.g.:

historyID = managementProxy.CreateReportHistorySnapshot(reportPath, out warnings);

However, if your code just calls CreateReportHistorySnapshot and the end user requests the report by clicking on the report link in the Report Manager or SharePoint (if the server is configured for SPS integration with SQL Server 2005 SP2), the user will get:

The selected report is not ready for viewing. The report is still being rendered or a report snapshot is not available. (rsReportNotReady)

This error is generated despite the fact that the report has history runs generated already. What’s going on? Why doesn’t the report server returns the last history run automatically? It turns out that the report snapshot and history runs are kept in two different places in the report catalog and are treated differently. To avoid this error change your code as follows:

managementProxy.UpdateReportExecutionSnapshot(reportPath);

ReportHistorySnapshot[] history = managementProxy.ListReportHistory(reportPath);

historyID = history[history.Length – 1].HistoryID;

The first line of code generates the report execution snapshot so clicking on the report link in the Report Manager would show the last snapshot. Assuming the report history for the report is enabled and “Store all report execution snapshots in history” option is enabled, this will also copy the report snapshot to the report history. The second line retrieves the definitions of all report history runs. Finally, the third line gets the last history identifier to return to the client if this is what the client is expecting.