Microsoft ReportViewer Control READONLY

4.2k views Asked by At

I successfully used the Microsoft ReportViewer Control on a webpage recently belonging to the Microsoft.Reporting.WebForms namespace. I used a property of the ReportViewer called Server.ReportServerCredentials to set the credentials (domain, user and password). I've been able to display reports which are on a remote server.

Now, I need to do something similar but I need the report in a windows form. The problem I'm having is that I'm using the control belonging to the Microsoft.Reporting.WinForms namespace and the property ReportServerCredentials is READONLY.

Why is it that for one control this property is readonly and the other not considering you need to set the credentials to access the report? How do I work around this?

3

There are 3 answers

1
richard On BEST ANSWER

This doesn't really answer your question per se, but I would skip using the WinForms report viewer. See my answer here for why, and how to do it a better way with a web browser (you could even leverage your Web app that already accesses the reports).

0
richard On

It's actually not read only.

Check MSDN - ReportServerCredentials class.

Here's how you would set the credentials.

ReportServerCredentials reportCredentials = new ReportServerCredentials();
//SET THE CREDENTIALS HERE A LA reportCredentials.ImpersonateUser etc.
rvReportViewerControl.ServerReport.ReportServerCredentials = reportCredentials;

Edit:

ReportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = reportCredentials.NetworkCredentials;
0
mouse On

Ue this code

dim myCred As NetworkCredential = New NetworkCredential("mmmmmm", "*****", "----")
ReportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = myCred

Unlike the webforms version of the ReportViewer control which requires you to provide an implementation of the IReportServerCredentials interface, the winforms version of the report viewer implements ReportServerCredentials directly. In your case, you can just assign your NetworkCredential object to ReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials.