How to launch an SSRS report in a browser window from a .NET application

By:   |   Comments (15)   |   Related: > Reporting Services Development


Problem

I am working on a .NET application where we have built many reports using SQL Server Reporting Services (SSRS).  A common complaint from the business users is that they don't want to open their browser and navigate to the Report Manager (or a SharePoint document library) in order to run their reports.  Ideally they would like to launch a report from within the application by choosing it from a menu or clicking a button.  Can you provide an example of how to do this?

Solution

There are a couple of ways that you can launch an SSRS report from a .NET application; you can:

  • Call the SSRS web service to render the report

  • Use a Report Viewer control in the application to render the report

  • Execute the report using URL access where the report will render in a browser window

Since the URL access method provides exactly what you need that is what I will cover in this tip.  This is probably the simplest way to render a report from an application; you just need to put together a URL that represents a report request and launch the browser.  When Reporting Services gets a URL request for a report, the default handling is to render the report as HTML.  The report rendering is exactly the same as if you ran the report from the Report Manager web application (or a SharePoint document library).

A Simple URL Request for a Report

A URL request for a report consists of the following parts:

  • Web service URL of the report server

  • Report path (library or folder and name of report)

  • Parameters for the report, the HTML viewer, or report server commands.  Take a look at the URL Access Parameter Reference for the complete details.  It is a best practice to specify rs:Command=Render to indicate that you want to render a report.

The URL request depends on whether Reporting Services is deployed as a native instance or a SharePoint integrated instance.  Check Access Report Server Items Using URL Access for the details.

If you are working with a native instance of SSRS, you can get the web service URL of the report server from the Web Service URL page in the Reporting Services Configuration Manager (the URL below is cut off; it is http://BARLEY-LAPTOP:80/ReportServer):

Web Service URL

BARLEY-LAPTOP is the name of my laptop computer where I have a native instance of SSRS installed; 80 is the port number where the web service is running.  When the web service is using port 80 you do not have to specify the port number.

Assuming I have a report named sample in the mssqltips folder, a simple URL request (without any parameters) would be:

http://BARLEY-LAPTOP:80/ReportServer?/mssqltips/sample&rs:Command=Render

Note that the web service URL for the report server and the report folder and name are separated by "?".

If you are working with a SharePoint Integrated instance of Reporting Services, the URL request follows the same format, but there are some slight differences:

http://SP2010WFE1/_vti_bin/reportserver?http://SP2010WFE1/mssqltips/sample.rdl&rs:Command=Render

The URL details are:

  • The web service URL of the report server is http://<SharePointSite>/<Sub-site>/_vti_bin/reportserver (sub-site is optional)

  • The SharePoint document library and report name is mssqltips/sample.rdl

Launching the Browser

Launching the browser and rendering the report is easy.  We can use the Start method of the System.Diagnostics.Process class in the .NET Framework.  Here is the single line of code that we need:

Reporting Services in native mode:

System.Diagnostics.Process.Start("http://BARLEY-LAPTOP:80/ReportServer?/mssqltips/sample&rs:Command=Render")

Reporting Services in SharePoint Integrated mode:

System.Diagnostics.Process.Start("http://SP2010WFE1/_vti_bin/ReportServer?http://SP2010WFE1/mssqltips/sample.rdl&rs:Command=Render")

When this code is executed the report will be rendered in a browser window.

Adding Parameters to the URL Request

In this section I will show an example of adding parameters to the URL request.  Reports typically have parameters that are used to filter the data shown on the report.  In addition you can specify parameters to control the HTML output such as whether to show the parameters section, toolbar, etc.

The following screen shot shows a report that was run from the Report Manager web application used with a native instance of Reporting Services:

Adding Parameters to the URL Request

The following is the URL request that includes the Sales Territory Group parameter and does not show the parameter text box (must be all on one line in code):

http://BARLEY-LAPTOP:80/ReportServer?/mssqltips/sample&rc:Parameters=false&rs:Command=Render&SalesTerritoryGroup=Europe

The following screen shot shows the report rendered in the browser via the URL request (note the parameters text box isn't shown):

The following screen shot shows the report rendered in the browser via the URL request
Next Steps
  • Rendering an SSRS report in a browser from a .NET application can be a better approach than forcing users to run them from the Report Manager or a SharePoint document library.
  • Take a look at the URL Access (SSRS) to review all of the capabilities that URL access provides. 
  • Download the sample code here to experiment on your own.


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Ray Barley Ray Barley is a Principal Architect at IT Resource Partners and a MSSQLTips.com BI Expert.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Monday, October 28, 2019 - 7:23:42 AM - Raymond Barley Back To Top (82918)

Try passing 2019%20Jan (or whatever 3 character month abbreviation)

The %20 is the URL encoding for a space.


Saturday, October 26, 2019 - 4:49:31 PM - Naga Back To Top (82907)

Hi Ray Barley,

I am working on some critical deliverable of reports to customers. As a requirement I am trying to pass parameters in URL but for some reason its not working. 

I have to pass two parameters

1.ReportingPeriod which has '2019 Jan','2019 Feb' etc so I am trying to pass &ReportingPeriod=2019+Jan

2.Country='USA','UK' etc so passing &Country=USA in URL link

my URL Link is https://abc.com/Reports/report/Temp/Country&rs:Command=Render&ReportingPeriod=2019+Jan&Country=USA

I checked no. of characters which is less than 260. 

Could you let me know if I am missing any.


Tuesday, March 6, 2018 - 7:48:20 AM - Joseph M. Morgan Back To Top (75360)

 I have a specific SQL server login that is only for reports from our data mart. I use this as stored credentials in the data source and eliminate the login prompt. This works well for reports that are delivered through an application that requires authentication first. The page that serves the reports is protected--each report is not.

I wouldn't recommend this for sensitive data but it works all right for generic reports.

 

Joey

 


Tuesday, October 10, 2017 - 11:53:12 AM - Adrian Back To Top (67160)

Hi Ray,

I just did all what you suggested and I worked perfectly, but It always ask for loggin the server. How do I configure this to avoid it?

 

Thanks

 


Friday, July 14, 2017 - 12:17:22 PM - Paytonn Back To Top (59350)

 This is the single most beneficial instruction set (for ANY process)  i have come across in months.   We have always used a cumbersome "open a report viewer page and select the report you want to print" which is fine for most of our work,  but we have a couple of items that would work so much better if we could just blast it onto their screen without any fiddling.  This fills that bill perfectly.  You have made me look like a true "customer service oriented" programmer.  Two thumbs up.


Monday, November 30, 2015 - 10:20:43 AM - Ray Barley Back To Top (40159)

I do not know if you can use a tool to compare SSRS databases and generate an update script to synchronize them.  

However, take a look at this tip which walks through using a tool called Reporting Services Scripter which might work for you.

https://www.mssqltips.com/sqlservertip/2627/migrating-sql-reporting-services-to-a-new-server/

 


Wednesday, November 25, 2015 - 10:13:25 AM - Jan Siegrist Back To Top (39140)

Newbie to SSRS here - just getting started. Great article.

Is it possible to RedGate differences in an SSRS database and come up with an update script?


Friday, March 14, 2014 - 9:50:13 AM - Raymond Barley Back To Top (29759)

Take a look at this article for an example of how to execute a report and render it as a PDF:

http://www.codeproject.com/Articles/15555/Generating-PDF-reports-programmatically-using-SQL

 


Friday, March 14, 2014 - 5:13:55 AM - Palanivelrajan Back To Top (29753)

Hai 

It is good article.

 

I would like to know, how to write the output of the webservice URL to PDF/EXCEL on a specificed folder in report server / share location without rendering/responding output to the request.

 

Thanks and Regards

Palanivelrajan

 

 


Monday, March 10, 2014 - 5:17:51 PM - Ray Barley Back To Top (29698)

Did you When you launched the browser, did you right click on it on the Start page then select Run as Administrator?


Monday, March 10, 2014 - 2:01:57 PM - Sultana Back To Top (29692)
  • I have created a report in my laptop using visual studio data tool.  when I click the web service URL it shows following information
  • "The permissions granted to user 'PAR-DBA\sqldba' are insufficient for performing this operation. (rsAccessDenied) Get Online Help " I tried with administrative previledge but same result. can any body guide me how can I solve it. I am using WINDOW 8

 



Wednesday, November 6, 2013 - 7:49:01 AM - Raymond Barley Back To Top (27418)

In an ASP.NET app you could use the Report Viewer web server control; see http://msdn.microsoft.com/en-us/library/ms251671(v=vs.110).aspx

 

 


Wednesday, November 6, 2013 - 4:43:31 AM - neilj Back To Top (27415)

Would this technique work for an ASP.Net webforms application?


Monday, September 16, 2013 - 1:04:53 PM - Raymond Barley Back To Top (26818)

The data source in the report uses windows authentication. 


Sunday, September 15, 2013 - 7:12:40 PM - bbh Back To Top (26802)

Truely you can do that; however, execute report outside the authentication is not recommended for small/large business. In corporate environment, I suggested a log, who, when, where execute the report.















get free sql tips
agree to terms