Microsoft ReportViewer 控件只读
我最近在属于 Microsoft.Reporting.WebForms 命名空间的网页上成功使用了 Microsoft ReportViewer 控件。我使用 ReportViewer 的一个名为 Server.ReportServerCredentials 的属性来设置凭据(域、用户和密码)。我已经能够显示远程服务器上的报告。
现在,我需要做类似的事情,但我需要 Windows 窗体中的报告。我遇到的问题是我正在使用属于 Microsoft.Reporting.WinForms 命名空间的控件,并且属性 ReportServerCredentials 是只读的。
为什么对于一个控件来说,该属性是只读的,而另一个控件则没有考虑到您需要设置访问报表的凭据?我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它实际上不是只读的。
检查 MSDN - ReportServerCredentials 类< /a>.
以下是设置凭据的方法。
编辑:
It's actually not read only.
Check MSDN - ReportServerCredentials class.
Here's how you would set the credentials.
Edit:
这本身并不能真正回答您的问题,但我会跳过使用 WinForms 报告查看器。请参阅我的答案此处了解原因以及如何更好地做到这一点Web 浏览器(您甚至可以利用已访问报告的 Web 应用程序)。
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).
使用此代码
与 Webforms 版本的
ReportViewer
控件要求您提供IReportServerCredentials
接口的实现不同,winforms 版本的报表查看器实现ReportServerCredentials< /code> 直接。在您的情况下,您只需将
NetworkCredential
对象分配给ReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials
即可。Ue this code
Unlike the webforms version of the
ReportViewer
control which requires you to provide an implementation of theIReportServerCredentials
interface, the winforms version of the report viewer implementsReportServerCredentials
directly. In your case, you can just assign yourNetworkCredential
object toReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials
.