VB.NET报表查看器问题

时间:2015-07-29 12:09:12

标签: sql-server vb.net reporting-services

所以我在局域网中有一个报表服务器,我想通过带有报表查看器的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

谁能帮我弄清楚什么是错的?提前谢谢。

1 个答案:

答案 0 :(得分:0)

有解决方案

        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