Sessionless ReportViewer Control

Microsoft ships a ReportViewer control that integrates with SQL Reporting Services to display reports on an ASPX page.  There's an older one for SQL 2000 Reporting Services, but specifically I'm dealing with 2005. It's pretty slick.  The only challenge is: getting the thing to work without session state. 

If you're trying to use the control to run reports in local mode without session state, you're hosed.  But that's ok, because most people tend to run them remotely.  According to this doc on MSDN, you can turn off session state IF you embed the connection information in the web.config.  To be honest, I don't really know why that is ... in this test case I specify the connection and credentials at run time, but nevertheless, you'll get an exception without this information.

The thing is, the doc is slightly wrong.  And since most people will be implementing the IReportServerConnection on a class that's in the APP_CODE folder, setting this up can be tricky.  That's where this info comes in handy.

First, the correct key is ReportViewerServerConnection, not ReportViewerConnection as specified in the MSDN doc.  (You can check by opening up the assembly in Reflector.)  It's a minor typo, but obviously critical.  So, if you think you've got everything correct but still seeing the same session state error, check the key name.  Next, to specify an assembly in the APP_CODE folder, make sure the setting looks like this in the appSettings element of the web.config (the same applies to HttpModules that may reside in the APP_CODE folder):

    <add key="ReportViewerServerConnection"
    value="Namespace.Classname, APP_CODE" />

That should clear up any problems getting the ReportViewer control to load ... of course, you need to implement that interface in the specified class.  Doing this can be tricky depending on the authentication used, so in some future post I'll show some code on implementing the IReportServerCredentials interface.

Comments (1) -

Brian Hartman - MSFT
Brian Hartman - MSFT
7/12/2006 8:13:40 PM #

To address your question about why the connection information must be specified in the config file:

The control uses the connection information while processing the aspx page to establish the report execution session and to get/set parameter information for the report, as well as a few other things such as retrieving the list of rendering extensions available on the server.

But the connection information is also needed after the page has finished executing for several operations.  If the control is running with AsyncRendering=true, the html for the report is retrieved after the page is rendered, by an iframe.  And in both sync and async modes, the images in a report are retrieved during separate requests using the report viewer http handler.  Exporting is also an asynchronous operation.

To handle these requests, the control acts as a proxy to the report server, which means it needs connection information.  With ASP.Net session enabled, this information can be retrieved from session.  But without it, we have two options - send the connection information to the client in html so that it can be sent back on the url for the async operation, or retrieve the information from the config file.  Sending the connection information to the client is an obvious security problem, so we use the config file.

Comments are closed

My Apps

Dark Skies Astrophotography Journal Vol 1 Explore The Moon
Mars Explorer Moons of Jupiter Messier Object Explorer
Brew Finder Earthquake Explorer Venus Explorer  

My Worldmap

Month List