Download Solution - ReportingTests.zip
There is an interesting thing that happens when you use Reporting Services 2005. You find that sometimes things don't quite work like you want them to and you don't know why. Such as sorting on a boolean (not going to happen). Or Rich textboxes. Nope, that's vNext. Or wanting it to actually USE the white space that I have put into the report instead of ignoring it on a web page (pre tag anyone?). So what you do instead is start looking for ways around these little annoyances. Then you come across a gem like this and you think it must be a bug. As for a workaround, I haven't thought of one yet.
Conditions:
- ASP.NET Report Viewer using Remote Reports
- Report that links to another report
- Both reports return more than one page
- Reporting Services installed
So what we've found is that when you have two reports where one navigates to the other, if you click on the second page of the second report, it takes you to the second page of the original report. If you click it again, it works appropriately. This is definitely a no-go for production code and this may delay our ship date because I would think this is definitely undesirable.
If you want to skip all of this, go straight to execution.
Web Application
So below you see I have a simple ASP.NET page where I am putting a button and a report viewer control on the page.
ASP.NET Page:
<%@ page language="vb" autoeventwireup="false" codebehind="Default.aspx.vb" inherits="ReportingTests._Default" %>
<%@ register assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Reports</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button id="btnSubmitReport" runat="server" enableviewstate="false" text="Submit" /> <br />
<rsweb:reportviewer id="rvReports" runat="server" processingmode="Remote" width="98%" height="800px" showparameterprompts="False" />
</div>
</form>
</body>
</html>
My code behind is also pretty simple. I am basically wiring up to the remote report and displaying it on the page. Again, not too much logic involved in that.
CodeBehind:
Imports System.Configuration
Imports Microsoft.Reporting.WebForms
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub btnSubmitReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitReport.Click
Dim rpt As ServerReport = rvReports.ServerReport()
rpt.ReportServerUrl = New System.Uri(ConfigurationManager.AppSettings("ReportURL").ToString)
rpt.ReportPath = ConfigurationManager.AppSettings("ReportPath").ToString & "/Main"
rpt.Refresh()
End Sub
End Class
The web.config file I have added two appSetting key's where I am pointing to the reporting services url and the report path where I deployed my report.
Web.Config:
<appSettings>
<add key="ReportURL" value="http://localhost/ReportServer"/>
<add key="ReportPath" value="/ReportTest"/>
</appSettings>
Data Project
I have also included a data project in the project that has a view and a sproc that need to be run on Northwind. If you don't have northwind installed you can download and install the one on Microsoft and install it on SQL Server 2005 and run it in SQL Server 2000 Compatibility Mode.
USE NorthWind
GO
CREATE VIEW vwCustomerOrders AS
SELECT
c.CustomerID
,c.CompanyName
,c.ContactName
,c.ContactTitle
,c.Address
,c.City
,c.Region
,c.PostalCode
,c.Country
,c.Phone
,c.Fax
,o.OrderID
,o.EmployeeID
,o.OrderDate
,o.RequiredDate
,o.ShippedDate
,o.ShipVia
,o.Freight
,o.ShipName
,o.ShipAddress
,o.ShipCity
,o.ShipRegion
,o.ShipPostalCode
,o.ShipCountry
FROM [Northwind].[dbo].[Customers] c
INNER JOIN [Northwind].[dbo].[Orders] o
ON c.CustomerID = o.CustomerID
DECLARE @SPName VarChar(100)
SET @SPName = 'uspOrderDetails'
IF NOT EXISTS(SELECT * FROM sysobjects WHERE [name] = @SPName)
BEGIN
DECLARE @SQL VarChar(1000)
SET @SQL = 'CREATE PROCEDURE ' + @SPName + ' AS'
EXECUTE(@SQL)
END
PRINT 'Updating Procedure ' + @SPName
GO
ALTER PROCEDURE uspOrderDetails
@OrderID Int
AS
BEGIN
SELECT
od.OrderID
,od.ProductID
,od.UnitPrice
,od.Quantity
,od.Discount
FROM [Northwind].[dbo].[Order Details] od
WHERE
OrderID = @OrderID
RETURN(0)
END
Report Project
Now we move onto the other side of the project and that is the two reports. These reports make a connection to Northwind.
The main report that pulls in all of the customer's and their orders.
The blue textbox above is where the Navigation to the second report occurs. It also passes a parameter.
The OrderDetail Report is below. You can see that it is also a pretty simple report. I inserted a page break at the bottom of the table to simulate a second page. The part with the line and below is what will be page two. This report takes a parameter input for OrderID and passes that to the stored procedure.
Execution and Bug
And now that we are done with all of the code, we can actually see what the bug is. I will give you a second to ensure all of the below is good.
- Ensure you have run both scripts on your Northwind instance.
- Ensure you have a good connection string for dsNorthwind (the data source) in the Reports project.
- Ensure that you have deployed the reports to the server by right clicking on the reports and selecting deploy.
- Update the web.config for any changes to the reporting server you may have made.
All ready? Great! Now we fire up the application and we get the main page. We click on the submit button and we get a report.
Now we click the link to take us to the other report. Go ahead, click on one of the links.
Now that you are in the second report, try to view the second page. Notice it takes you back to the first report.
Click on another link in that first report. Now click on the second page. Now you stay on the second report.
This bug brought to you by Microsoft. :D
Only in ASP.NET. Only with SQL Reporting Services. If you made it this far it means you are probably responding to the post in Microsoft forums for this bug. :D