1
votes

So I have a report server in a local area network that I want to access via a winform application with a Report viewer

my Report viewer control Name is rpt_ReportViewer and here's the Code to view reports on the 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

whenever I run this code it generates an exception in the report viewer saying "The Request Failed with HTTP Status 401: Unauthorized."

I don't know whats wrong but I used this very same code on a localhost and it worked http://localhost/reportserver

can anyone help me figuring out whats wrong please ? thanks in advance.

1
I think you may need to provide user credentials as well. - Karlta05
@Karlta05 thanks I solved it and you are right it needed credentials to access the server - Willy
You should post your solution to help any others that may encounter the same problem that you had. Glad you solved it as well. :D - Karlta05
Done , and thanks! :) - Willy

1 Answers

0
votes

There's the solution

        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