Showing posts with label SSRS. Show all posts
Showing posts with label SSRS. Show all posts

Wednesday, May 21, 2008

SQL Server Reporting Service (SSRS) - HTTP Status 401 Unauthorized Error

I am going to continue on writing article on SQL Server Reporting Services (Its because, it is providing me good fame on http://forums.asp.net, LOL smile_wink).

We have to deploy the reports on the the Reporting Services Virtual Directory (I can write the whole different article on the Reporting Deployment, but may be next time. Right now we don't want to go deep into that.). The Reporting Server Virtual Directory may exist on the different server. It is recommended to keep anonymous access off for Reports virtual directory if you are going to call reports on the web.

The anonymous access allows any user to access the page. But now when we are keeping anonymous access off for the Reports, it can create problem while fetching the report inside the Report Viewer control on any ASPX page.

The Report server will expect authorized user to access the reports. This can be done by two ways.

  1. Passing the Report Server User Credentials with the Reports.
  2. Forms Authentication on Reporting Server.

Today, I am going to explain that How can we pass the User Credentials of the Reporting Server with the report call.

We need to Create one sealed class to perform this action. This class need to be inherited from IReportServerCredential interface.

    [Serializable]
public sealed class ReportServerNetworkCredentials : IReportServerCredentials
{
#region IReportServerCredentials Members

/// <summary>
/// Provides forms authentication to be used to connect to the report server.
/// </summary>
/// <param name="authCookie">A Report Server authentication cookie.</param>
/// <param name="userName">The name of the user.</param>
/// <param name="password">The password of the user.</param>
/// <param name="authority">The authority to use when authenticating the user, such as a Microsoft Windows domain.</param>
/// <returns></returns>
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName,
out string password, out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;

return false;
}

/// <summary>
/// Specifies the user to impersonate when connecting to a report server.
/// </summary>
/// <value></value>
/// <returns>A WindowsIdentity object representing the user to impersonate.</returns>
public WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

/// <summary>
/// Returns network credentials to be used for authentication with the report server.
/// </summary>
/// <value></value>
/// <returns>A NetworkCredentials object.</returns>
public System.Net.ICredentials NetworkCredentials
{
get
{
string userName = "SERVERUSERNAME";
string domainName = "DOMAIN";
string password = "somepassword";

return new System.Net.NetworkCredential(userName, password, domainName);
}
}

#endregion
}



How to Utilize the ReportServerNetworkCredentials Class in your Report call on Page_Load event...



protected void Page_Load(object sender, EventArgs e)
{
myReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;

// Here we are going to pass the ReportServerCredentials to the Report Viewer.
myReportViewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();

ReportServerLoaction = ConfigurationManager.AppSettings["REPORT_SERVER_PATH"];
myReportViewer.ServerReport.ReportServerUrl = new Uri("http://MyReportServer/Reports/");
myReportViewer.ServerReport.ReportPath = "TempReports/MyFirstReport";
myReportViewer.ShowParameterPrompts = false;
myReportViewer.ShowPrintButton = true;

Microsoft.Reporting.WebForms.ReportParameter[] reportParameterCollection = new Microsoft.Reporting.WebForms.ReportParameter[1];
reportParameterCollection[0] = new Microsoft.Reporting.WebForms.ReportParameter();
reportParameterCollection[0].Name = "ClientID";
reportParameterCollection[0].Values.Add("49020644-63AA-4D92-81A1-8F85D49ACF67");

myReportViewer.ServerReport.SetParameters(reportParameterCollection);
myReportViewer.ServerReport.Refresh();
}



Please feel free to comment on the article. Critics are highly appreciated.

Saturday, May 10, 2008

SQL Server Reporting Services (SSRS) Versus Browser Compatibility

 

Microsoft has released SQL Server Reporting Services(SSRS) as server based report generation and development environment in 2004. It was released as SQL Server 2000 extension. SSRS has been released directly to the competition of Crystal Report and other Business Intelligence tools. The current version of SSRS is shipped with SQL Server 2005.

The file format of SSRS reports is .rdl. The RDL is XML. The RDL can be exported to PDF, XML, Excel, TIFF, CSV, HTML. Apart from this, you can call the report by simple URL.

Sounds Good...!!!!!

But, with all these coolest features of SSRS, there are plenty of bugs too. First ever bug I encounter is Browser Compatibility. There is pretty big issue with SSRS reports browser compatibility. The reports are best view in only IE6 and above. In this competitive world, we need to provide browser compatible websites. SSRS can be big hurdle in your website against browser compatibility.

We experienced a problem with the multivalue parameter dropdown in ReportViewer control in FireFox. It was working fine in IE. The calendar control and the multivalue dropdown was having problem. The problem caught me when I click on the calendar control, the calendar appears and then quickly disappeared before I can select anything. It was just in frequence of second. Wow, it was pretty quick and it became a challenging game for me to catch it. But Microsoft was very quick and I never could catch calendar.

The problem was with ReportViewer control provided by VS2005. When we call report directly in Firefox browser using report URL, it was working perfectly fine. So, finally we came to conclusion that, the problem is only due to ReportViewer control.

The solution to resolve the issue is very strange. We need to remove the DOCTYPE tag from the HTML. Removing DOCTYPE tag can create lots of issues with HTML and CSS layouts. But we have to rectify other issues.

Developers of ReportViewer control has used some nonstandard methods and attributes like onactive event. The page contains specific DOCTYPE, will not parse such events. We tried to use other DTDs like, HTML 4.0 and HTML 5.0 but nothing help. Finally we removed the DOCTYPE and problem get solve (And other design related problem start arising smile_sad).

For more in SSRS please visit Paresh Jagatiya's Weblog.