Friday, March 23, 2012

Report Viewer

I am trying to view my reports using the Report Viewer control. Here is my code :

<rsweb:ReportViewerID="ReportViewer1"runat="server"Font-Names="Verdana"Font-Size="8pt"Height="400px"ProcessingMode="Remote"Width="400px">

<ServerReportReportPath="https://ReportServer/Reports/Pages/Report.aspx?ItemPath=%2flovelyjubb%2fReports%2fQBRatings"ReportServerUrl="https://ReportServer/reports/Pages/Folder.aspx"/></rsweb:ReportViewer>

But when I run the code I get the error :

'The request fails with HTTP status 401 : unauthorized'

How do I prevent this error?

Thanks,

Mike

Does your server requires any authentication? If it does you can set the report programmatically from the code behind.

Here is some example i've used some time ago, it should still works :)

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
deimosReportViewer.Visible = false;
// Create a Web service proxy object and set credentials
ReportingService rs = new ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Return a list of catalog items in the report server database
CatalogItem[] items = rs.ListChildren("/", true);

// For each report, display the path of the report in a Listbox
foreach (CatalogItem ci in items)
{
if (ci.Type == ItemTypeEnum.Report)
catalogListBox.Items.Add(ci.Path);
}
}
}
protected void loadBtn_Click(object sender, EventArgs e)
{
string catalogItemPath = catalogListBox.SelectedItem.Text;

// Create a Web service proxy object and set credentials
ReportingService rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

deimosReportViewer.Visible = true;
Uri reportServerUrl = new Uri("http://deimos/reportserver");
deimosReportViewer.ServerReport.ReportServerUrl = reportServerUrl;
deimosReportViewer.ServerReport.ReportPath = catalogItemPath;
}

Cheers,

Yani

|||Your code is similar to the code I used to use for RS 2000, but now I have switched to RS 2005 I have been advised to use the Report Viewer rather than code.sql

No comments:

Post a Comment