Accessing SSRS Reports Using Report Viewer


Introduction

Reports developed in the report
designer need to be published to the report server in order to make them
available to the end users. Once the reports have been deployed on the report
server they can be managed through the report manager web application but that
is more relevant to a site administrator as opposed to regular business users.

Accessing Reports using a Web Application

The best way  to provide access to
reports deployed on the report server is through the report viewer component
which  comes bundled with the .NET framework. This article give an overview on how
you can use the report viewer component to access the reports deployed on the
report server. The report viewer component requires you to specify the report
server address as well the report path, unfortunately setup is not as simple as one would imagine. Reporting services works strictly on the security model
with the role based access security to provide access only
to users who are authorized to view the report.

Lets work through a step-by-step example :

1. Open Visual Studio
and select a new project as website and select ASP.Net as your project
Template. Enter an appropriate name for the project and Click OK.

2. Add a webform and
name it, I used basic.aspx. The values for the configuration
settings have been already specified in the web.config in app settings tag :

The reason for specifying it in web.config
is that you can easily change the report server name and the access credentials when
deploying the web application in the production environment.

In my case I have specified localhost
as my server name, you can specify the machine name also if you wish but I
would recommend localhost as best practice .

The reportserver is the default instance, therefore
if your instance is a named instance please specify the name as
reportserver_instancename as the name of the reportserver.


The username is the user who can access the
report server and finally the password to connect to the reportserver.

3. Add the report viewer
component to the basic.aspx page and specify the report server and the report folder
in which you will be deploying the report.

4. You will need a
credentials.cs file (attached with this article) to pass the report
credentials to the report server. This because the user can be a part of the
local machine or the domain, and the reportserver will need to validate that
user before allowing access to the reports on
the report server. The credentials.cs file will do the necessary. You can also
 define it in the aspx.cs file but I have defined it separately for better code separation.

5. I added the
berlow code to it to initialize the report server with the credentials which
have the appropriate rights on the report server to access the report.

Make sure you have added the reference :

using Microsoft.Reporting.WebForms;

otherwise the web app will not recognise the reporting classes.

The above code builds up the connection string with the
values specified in the web.config to initialize the reportserver at run-time.

6. I
have defined and deployed a test report on the reportserver which I will be
accessing through the webpage using the reportviewer component. We can see
the report datasources and reports folder deployed on the reportserver. The
report test.rdl will be accessed in the front end using the webpage which we
have just designed.

7. Build
the web application and run it using the play button on the menu bar (or F5).

8. Once
the application is running, a browser window opens with the deployed
report.

Select the parametric values and view the report using
the reportviewer component .The following report is shown in the reportviewer

Conclusion

Thus we can easily access the SSRS reports from the front
end using the report viewer with the user having appropriate permissions on the
report server. In the next article we will see how to pass the parameters to
the report from the webpage.

The project can be downloaded here.




Array

2 Responses to “Accessing SSRS Reports Using Report Viewer”

  1. Thanks for the great article…is the Report Viewer browser agnostic? Will it work on the different flavors of mobile devices?

  2. Hi,

    In this demo report, i need a sub report which should be accessed by clicking the address id. Could you help me to proceed

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |