因此,我在局域网中有一个报表服务器,我想通过winform应用程序与报表查看器访问该服务器。
我的报表查看器控件名为rpt_ReportViewer,下面是查看reportviewer rpt_ReportViewer上报告的代码
Private Sub rpt_GenerateReportBtn_Click(sender As Object, e As EventArgs) Handles rpt_GenerateReportBtn.Click
With rpt_ReportViewer
.ServerReport.ReportServerUrl = New Uri("http://SERVER/ReportServer")
.ServerReport.ReportPath = "/Search Assets Table/Search Assets Table"
.RefreshReport()
End With
End Sub
每当我运行这段代码时,它都会在报表查看器中生成一个异常,上面写着“请求失败了,HTTP状态401:未经授权”。
我不知道出了什么问题,但是我在本地主机上使用了相同的代码,并且它运行了http://localhost/reportserver
有人能帮我弄清楚出了什么问题吗?提前谢谢。
发布于 2015-07-29 08:16:54
有个解决办法
Dim Credential As New NetworkCredential("User name", "Password") 'Was missing this Line
With rpt_ReportViewer
.ServerReport.ReportServerCredentials.NetworkCredentials = Credential 'Was missing this line too
.ServerReport.ReportServerUrl = New Uri("http://SERVER/ReportServer")
.ServerReport.ReportPath = rpt_ReportsListBox.SelectedValue
.RefreshReport()
End With
https://stackoverflow.com/questions/31700016
复制