Tuesday, June 3, 2008

How to create a parameterized report with Reporting Services

please see the clip

I assuming you have already read the previous posts about Reporting Services and you familiar with creating report. Let's say you have the same project in previous post. And you need to show just post code information that is in just one specific State. I am going to explain how to create a state parameter.

Open the report then go to Data View and select"New DataSet..."

Then all you need write a query to show all the states like this:

Then Select the previous data source and change the query as below. Remember when your query has some parameters (in reporting service @variable is a parameter) it will be automatically added to Report Parameters

So this query will need a state to run. From Report menu select Report Parameters you need to select "From query" radio button from "Available values" and also set the default value. As below (for more information see the clip)

The result should be like this:


please see the clip

Monday, June 2, 2008

How to show a report of reporting services from .net applications

After deploying your reports to report server, you need to access these reports and show them in your custom .net applications. This post will help you to do this task. Please see the clip that shows you how to deploy your report and how to access them.

Let's say you have a web application that needs to show reports. Firstly, you need add the ReportViewer control from toolbox (which is in data tab) to your page. Then you need to write some code to load report inside the ReportViewer probably you write this code either in page load or in a button click. Take a look to this code:

ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("emady", "mypassword", "hhi");

ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://falcon/Reportserver");

ReportViewer1.ServerReport.ReportPath = "/Report Project State/Report1";

ReportViewer1.ProcessingMode = ProcessingMode.Remote;

ReportViewer1.ServerReport.Refresh();


The first line is trying to pass the credentials to server. Second line is the Reportserver address. Third line specifies the Report address which has Report folder address and the report itself. Forth line sets the processing mode to Remote because you are accessing the report from other application. Finally you need to call Refresh to show the report.

The very tricky part about above code is that I used a Custom class Called ReportCredentials to apply my credentials to the Report server. The reality is that you need a valid credential to access report server so you need to pass this credential by this class which is inherited from IReportServerCredentials. Take a look at the source of this class:

public class ReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials

{

string _userName, _password, _domain;

public ReportCredentials(string userName, string password, string domain)

{

_userName = userName;

_password = password;

_domain = domain;

}

public System.Security.Principal.WindowsIdentity ImpersonationUser

{

get

{

return null;

}

}

public System.Net.ICredentials NetworkCredentials

{

get

{

return new System.Net.NetworkCredential(_userName, _password, _domain);

}

}

public bool GetFormsCredentials(out System.Net.Cookie authCoki, out string userName, out string password, out string authority)

{

userName = _userName;

password = _password;

authority = _domain;

authCoki = new System.Net.Cookie(".ASPXAUTH", ".ASPXAUTH", "/", "hhi");

return true;

}

}