Integrating Reporting Services 2005 Into a Web Application

This article provides step-by-step instructions on how to integrate a MS Reporting Services report into an ASP.NET web application using the ReportViewer control. It also includes an HTML template than can be used for the layout and tackles a couple of known problems with the ReportViewer control.

Introduction

With release of Visual Studio 2005, Microsoft has made it much easier to integrate its SQL Reporting Services into ASP.NET web applications. Most desired functionality of Reporting Services can be achieved through its ReportViewer control, which is the focus of this article. For those of you who need very fine and detailed customization of embedding RS reports into applications, I would recommend that you seek out articles that discuss the RS object model and its soap interface. Otherwise, this article should provide you with a good tutorial on how to integrate Report Services into a web application using Visual Studio 2005.

Step-by-Step Instructions

Go ahead and start up Visual Studio 2005. Click on the “New \ New Website” item in the file menu. In the dialog box select the ASP.NET Website, your language preference (C# is used in this article), and where you would like your website to be built. Click on OK.

One of most difficult tasks in embedding the ReportViewer control is ensuring that it fills 100% of the space you want it to fill, no more, no less. You also want the ReportViewer to use its own scroll bars, not the browser’s.

The code I have written is basically a template that you can use which sets an area for a header, a custom control bar, and the report itself.

Since the ReportViewer has difficulty taking up 100% of the space in a table (probably not 100% XHTML), you are going need to remove any XHTML settings.

If any of the users will also using the Mozilla browser, change the body tag so that the height is 99.3%. This is to avoid a double vertical scroll bar effect where you see both the ReportViewer’s scroll bar and the browser’s scroll bar. There will be an almost unnoticeable space at the bottom of Mozilla browser. Take note, that the contents within the ReportViewer may not display correctly (nor will they in Report Manager). So develop reports for Mozilla at your own risk at this time.

Go ahead and switch to the “Design” view since it is now time to add the ReportViewer control.

In the “Data” section within the Toolbox, drag the ReportViewer control onto the last row of your table, which should be taking up most of the page. Next you want to set the control’s properties so that it points to the right server and the right report. Under properties, go to the “Server Report” section. Right above the section you should see a property called “ProcessingMode”. In most cases you are going to want use an instance of a Report Server. So for the purposes of this tutorial, set this property to “Remote”, even if the Report Server instance is on the same computer as your web app. Next, you want to set the “ServerReport” settings.

First, type in address of the Report server in the “ReportSeverUrl” field.

The syntax is:

http:// NameOfServer / reportserver

i.e. http://ServerOne/reportserver

Next type in the location of the report in the “ReportPath” field.

i.e. /MyReports/TheReport

The location is easy to know since it is the same path structure that you see in the Report Manager. Also, always be sure the put a forward slash first before the actual path.

Unless you want the ReportViewer to be an absolute size, go ahead and set the height and width settings under the “Layout” section to be 100%. The ReportViewer will by default show controls to set the parameters for the report. These often look a little ugly, and I would recommend most developers to create their own parameter controls. This can be done in the control bar row of the template provided above. To get rid of the ReportViewer’s parameter controls set the “ShowParameterPrompts” in the properties underneath “Appearance” to false. In, the next section I’ll show how you can set the report parameters with your own code.

Those should be all the settings you need to make for the ReportViewer to display correctly, unless your version of Visual Studio has other default settings. Double check to make sure the ASP.NET looks similar to this code:

Now, the report is ready to be processed. You can go ahead and preview your website and the report should generate just fine.

Displaying a Report through the C#/VB Code

In many cases, you may need to pass parameters to a report or your code (or the end users) may need to have control over which report is generated. For example you may have a Drop-Down-List that lets the user select which report they wish to view. They can then click on a button that generates the report that accepts a parameter for the current time. (The Button and Drop-Down-List can be placed in the custom control bar section of the template.)

So the code inside the “Click-Button-Event-Handler” function is where we will need to put in our custom ReportViewer code. The code in this article is C#, but the VB code shouldn’t be too much different.

First, if you didn’t set the Report Server Url via the visual designer, you can do it here.

One problem/bug that is rather common in the ReportViewer control is when you change to a different report via the website itself coming from a drill-through report, an ASP.NET error can occur. This is because the ReportServer is thinking that the new report is still a drill-through when it is not. To get around this problem use the following code:

If you like you can delete the ReportPath from the properties in the visual designer. This will ensure that a report does not load until your own code loads a report itself. However, this will also remove the ReportViewer control bar, which you may wish to keep so that the website looks more structured. What I usually do is set the default ReportPath to point to a report that is basically a welcome screen. From there, the end user can choose parameters from my selection controls, and then when ready, the user can click on a view button that generates the desired report.

Conclusion

The ASP.NET code I have provided is code that I have used myself in different projects. Although I am personally more focused on software programming than web design, I do try to make my web pages 100% XHTML. Unfortunately, I was unable to completely stick to that standard because of the ReportViewer’s own HTML coding. If anyone has a 100% XHTML solution, which allows the DOCTYPE tag to be set to at least XHTML transitional, that can display RS reports sized to 100% inside a table, and allow the ReportViewer control to use its own scroll bars, I would be glad to revise this article. Otherwise, the template I have provided, should allow you to embed a nicely displayed RS report in a web page that can be process by the IE-based browsers .

Furthermore, this is only a solution for the IE browser. The layout template will work fine with Mozilla, but the ReportViewer's own HTML coding will not. This, of course, may change with new versions of the Mozilla browser.

If you wish deviate a little from this article in areas such as showing the ReportViewer parameters prompts, then the website may not show visually want you want. However, it should be easy enough to take my HTML code and tweak it (i.e. adding/removing border lines) so that it suits your needs.

As for the C# code, the only thing that may be confusing is the while loop to drill back to the parent report. Seemingly the Refresh() function should do this automatically, and yet, it will only give you an ASP.NET error. Hopefully, this will be fixed in later versions of the ReportViewer control, but for now the loop is a good go-around for this problem.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Hi.
Excellent article. However, I think there is a better solution for those of you that need to keep the "XHTML 1.0 Transitional" element on the page. Just put width='960px' and height='600px' on the <td> tag containing the report viewer control. Then, at the bottom of the page, insert:
<script language="javascript">
if (document.getElementById("rptViewer") != null) {
document.getElementById("rptViewer").style.display="inline";
}
</script>
where "rptViewer" is the name you've assigned to your report control. That will replace the default "display:inline-block" inserted by the control and show the scrollbars as needed. By the way, I'm using AsyncRendering=True.

I've managed to figure this out by creating schedules in Report Manager and checking what happens in the ReportServer database. The outcome was quite simple

Not sure whether you've resolved this, to create the daily ocurrence you only need the DaysOfInterval as the other two options "On the following days", and "Every Weekday" are in essence weekly occurrences.

I removed the DOCTYPE tag completely and kept the kept the 'target schema for validation' to default "XHTML 1.0 Transitional (...)". I set the layout to 100% for width and height. Then, I played around with "AsyncRendering" property of the ReportViewer. When the property was true, the scroll bar for the ASPX page got disabled but I could use ReportViewer's scroll bars. When the property was set to false, ReportViewer did have have any scroll bar and the report scrolling worked with the ASPX page scroll bar.

Not sure if this answers you question "Unfortunately, I was unable to completely stick to that standard because of the ReportViewer’s own HTML coding. If anyone has a 100% XHTML solution, which allows the DOCTYPE tag to be set to at least XHTML transitional, that can display RS reports sized to 100% inside a table, and allow the ReportViewer control to use its own scroll bars,...".

I have uploaded several reports on the Report server and calling them from via web application (ASP.Net with VB.Net).
As you know about one of a great feature of Report server is to subscribe the report. I want to give this feature also to the user of this applications.
So is this possible to code in such a way that a user can subscribe report according to his/her schedule?

I use IFrame and set the src path programmaticcaly.
My problem: I don't want the toolbar so I put rc:Toolbar = false, in IE6, the image of my report is not load.
I've no image. I haven't this problem under Firefox.

If I set the Toolbar at true, the report is rendered good under IE6.

How can I render the report in an iframe without the toolbar under IE6 ??

I tried the code and it works fine. When I translated it into VB.net, it doesn't work.
I got error message on this line: ReportViewer1.ServerReport.SetParameters(RptParameters)
The error message is: Value cannot be null.

RptParameters(1) creates an array with two elements and since only one is added, the second is null, which raises the exception. This is probably sooooooo obvious to many but I have just started trying VB.net (and VB in general). I spotted it in the VWD Express debugger.

First,
Thanks! You saved my bacon. I have built a relatively simple web-based report viewer and was going along fine until I drilled into a report. When I tried to to reassign the ReportPath to show another top-level report I got the "in this state" error and was pulling hair out! Thanks again for finding that. I also now know that I can't assign the ServerReport to a variable and check that after running the PerformBack. As long as I fully qualify the ReportViewer and don't try to assign any portion of it, it works just fine!
I do have another question though. Is there a way to plug into the event handler when the reports are running server-side? I want to capture the drilldown request and be able to do some client-side updates based on the new report (I'm building a breadcrumb control).
It appears I should be able to get to the event stack by setting up my own handler - ala...

Hi,
i am new to ''Sql Server 2005 Reporting Services''
how to Create the Reporting Services in Asp.net 2.0 with C#.(Please Clear Explanation with Screen Shots)
i am using the asp.net 2.0 ,sql server 2005 with SP2 in XP.
Please help me on this(Urgent)

I've created a SSRS report that take a parameter. When I run the .rdl it works great. I select the value from the parameter drop-down and it works great. Now I'm trying to build a web client to run the report but my code below says the parameter doesn't exist (line 9). I've verified that the parameter value that I pass in from the drop-down list (line 2) has the correct value.

I almost never program in VB, but it looks like you're not instantiating the array.

'Create an array of ReportParameter objects with one element
Dim params() as ReportParemeter = new ReportParameter(0)
'take the first element and assign it a ReportParameter object
params(0) = New ReportParameter("PortalId", intPortalId, True)

my requirement is:
i want to pass multiple perameters from one web page to other one.the other one containts reportviewer contol.by using that perameters report will be generated...is it possible?
i need c#.net code with some example...
plase help me ...
multiple perameters means:
example...

let id is one perameter..it accepts the multiplevalues id=1,2,3 like that

in aspx form: id=1,2,3.. if i enter like this
report will genarate .all the details of ids 1,2,3
query:select * from table1 where id=@id;
reportpreview:

1.I change the validation to IE 6.0 to add “scroll=no” in the body of the page in order to have one scroll bar.
2.I have a menu at the top of the page which is not render correctly unless I add something like :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
3.I can not use height =100% because of the menu height is there a way to measure the remaining height and assign it to the Report Viewer.

hi there
i read your article and it's so cool, i've developed a search page and integrated with Reporting services and i've went through the steps you showed in your article, when testing my report on it's own it's works but on the web application the viewer doesn't show anything but shows that the report is being generated but nothing.
here's the code:
protected void bSearch_Click1(object sender, EventArgs e)
{
//to do take the params and fire search
this.type = Convert.ToString(this.ViewState["SEARCH_TYPE"]);
this.ReportViewer1.Visible = true;
Microsoft.Reporting.WebForms.ReportParameter[] RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[6];