The request failed with HTTP status 401: Unauthorized. RRS feed

  • Question

  • User702850808 posted

    I trying get ssrs 2008 up and running on a new server.

    I got everything to work just like it dit on my old server and I can deploy reports and view them in the report manager, but I cannot seem to view a report from asp.net applications either in a reportviewer or using the reportexecutionservice. I keep getting the error: The request failed with HTTP status 401: Unauthorized

    This is the first time that I had to set up ssrs so I do not know whether I have missed something. I tried to make everything the same as the instance on my old server.

    The following code is what I use for the web execution service and it used to work fine.

    This code basically just renders the report as a pdf and downloads it.

     rs.Credentials = New System.Net.NetworkCredential("username", "password", "domainname")
                    Dim reportPath As String = "/OLS/" & ReportName
                    Dim ResultStream() As Byte
                    Dim StreamIdentifiers() As String = Nothing
                    Dim optionalParams(1) As ParameterValue
                    Dim OptionalParam As String = Nothing
                    Dim optionalWarnings As WebReference.Warning() = Nothing
                    optionalParams(0) = New WebReference.ParameterValue
                    optionalParams(0).Name = "WarningID"

                    optionalParams(0).Value = Session("ID")
                    ' Create and set the content type string
                    Dim contentType As String = "application/pdf"
                    Dim historyID As String = Nothing
                    Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
                    Dim format As String = "PDF"
                    Dim extension As String = ""
                    Dim encoding As String = ""
                    Dim mimeType As String = ""
                    Dim warnings As Warning() = Nothing
                    Dim streamIDs As String() = Nothing

                    Dim WarningID As String
                    WarningID = Session("ID")

                    Dim execInfo As New ExecutionInfo
                    Dim execHeader As New ExecutionHeader()
                    rs.ExecutionHeaderValue = execHeader
                    execInfo = rs.LoadReport(reportPath, historyID)
                    rs.SetExecutionParameters(optionalParams, "en-us")
                    Dim FilePath As String
                    FilePath = "c:\WebDocuments\OLS\TempDocs\" & Session("EmployeeID") & "\"

                        ResultStream = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

                        execInfo = rs.GetExecutionInfo()

                        Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

                    Catch err As SoapException
                    End Try

                    ' Write the contents of the report to an MHTML file.
                        Dim stream As FileStream = File.Create(FilePath + WarningID + ".pdf", ResultStream.Length)
                        Console.WriteLine("File created.")
                        stream.Write(ResultStream, 0, ResultStream.Length)
                        Console.WriteLine("Result written to the file.")
                    Catch err As Exception
                    End Try


                    ' ResultStream = rs.Render("/" & sReportPath & "/" & sReportName, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", optionalParams, Nothing, Nothing, OptionalParam, OptionalParam, optionalParams, optionalWarnings, StreamIdentifiers)
                    Response.ContentType = "application/octet-stream"
                    Response.AddHeader("Content-Type", contentType)
                    Response.AddHeader("Content-Disposition", "attachment;filename=" & WarningID & ".pdf")

                End Using

    Monday, September 1, 2014 9:23 AM


  • User1519735232 posted

    Generally, the 401 error occurs when the user is not authorized to the Report Server. Besides, if Reporting Services is configured to use Kerberos, however, we didn't register Service Principal Name (SPN) for the account the Reporting Services is running under, this error will occur as well.

    To solve the issue, please follow these steps:

    1. Make sure the user is able to connect to the Report Server.
    2. If using Kerberos authentication, please make sure SPN is configured correctly.

    For more information about Kerbero Authentication and how to register SPN for a report server in Reporting Services, please see the link Syed provided above and the articles below:

    If you have any more questions, please feel free to ask.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 7, 2014 9:33 PM