The request failed with HTTP status 401: Unauthorized IN SSRS
Asked Answered
Q

9

12

My Application is in Asp.Net MVC3 coded in C#, i have a SSRS solution in SQL Server Business Intelligence Developement Studio in Visual Studio 2008 , I'm calling the SSRS report through my Asp.Net MVC3 application. My application was running fine a couple of days back but suddenly i'm getting an error as follows:

My Error :

The request failed with HTTP status 401: Unauthorized.

My Attempts

  1. My SSRS reports are deployed on my local server. I have my credential properly set in the datasource of my SSRS report solution.

  2. I tried to add the tag in my web.config <identity impersonate="true" userName="Domain\username" password="Password" />

  3. I tried adding IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");

  4. I ran the Visual Studio as 'Run as Administrator'.

  5. I tried the solution mentioned in this link Creating a key using RegEdit

  6. Update I tried the following solution as well but the same result : Unauthorized error in SSRS

None of the above solutions worked, but when i run the same solution on some other machine than the solutions works well and no error is displayed. Its only when i run the solution from my machine then i get the error The request failed with HTTP status 401: Unauthorized.

Quantify answered 8/10, 2013 at 12:25 Comment(2)
@KuldipMCA Actually, no idea how it got fixed. The other day i tried my solution and it did not had the same problem. Quite strange.Quantify
First thing to do is to make sure you can connect to database with SQL Server Management Studio, The login windows will either have Windows Credential or SQL Credentials. Most likely you have Windows Credentials and connection string must be Integrated Security = True (no username or password). Then check with SSMS that you ca perform a query. The login windows of SSMS has a server name and password and connection string needs the same. Finally after you get above correct if you have issues check the log file in SSMS under the Management explorer tab.Stelly
V
5

I am also getting the same error,

The request failed with HTTP status 401: Unauthorized.

Let me share what I tried and it is working fine now.

public class CustomSSRSCredentials : IReportServerCredentials
    {
        private string _SSRSUserName;
        private string _SSRSPassWord;
        private string _DomainName;

        public CustomSSRSCredentials(string UserName, string PassWord, string DomainName)
        {
            _SSRSUserName = UserName;
            _SSRSPassWord = PassWord;
            _DomainName = DomainName;
        }

        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get { return new NetworkCredential(_SSRSUserName, _SSRSPassWord, _DomainName); }
        }

        public bool GetFormsCredentials(out Cookie authCookie, out string user,
         out string password, out string authority)
        {
            authCookie = null;
            user = password = authority = null;
            return false;
        }
    }

Inside page_load event,

if (!Page.IsPostBack)
{
    ReportViewer1.ProcessingMode = ProcessingMode.Remote;
    IReportServerCredentials ssrscredentials = new CustomSSRSCredentials("MyUserName", "MyPassword", "ServerName");
    ServerReport serverReport = ReportViewer1.ServerReport;
    ReportViewer1.ServerReport.ReportServerCredentials = ssrscredentials;
    serverReport.ReportServerUrl = new Uri("ReportPathKey");
    serverReport.ReportPath = "/Reports/MyReport";
    serverReport.Refresh();
}

This worked for me!

Volkan answered 4/11, 2015 at 11:32 Comment(2)
hey pedram, what should I fill into the "ServerName" ? my server name is 160.00.00.00/myreport. I tried 160.00.00.00 but no lucky, also 160.00.00.00/myreport and /myreport, no one work for meZealand
excellent contribution, it works wonderfully for meRosierosily
M
3

I had the same problem. Everything worked fine and then suddently I receive a 401 in the reportviewer iframe instead of my report in debug mode (localhost). I had been fiddling with settings to get it running on the live site so I thought I did something wrong...

Tried several things and then decided to just reboot and guess what??? My domain password had expired so authentication failed!!! Stupid stupid stupid me!

Thought I'd add my solution here in case people run into the same stupid situation and loose precious time figuring out what they did wrong...

Midiron answered 17/1, 2017 at 13:54 Comment(0)
E
2

Try this

public void GetConnectionOfReportServer()
        {
            try
            {
                NetworkCredential credential = new NetworkCredential("administrator", "password@123", "Domain");
                this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;

                //select where the report should be generated with the report viewer control or on the report server using the SSRS service.
                this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://localhost/ReportServer");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
Elvyn answered 8/10, 2013 at 12:39 Comment(0)
D
1

The problem I had was my ReportPath. I was using the URL rendered one in the browser but instead should have been using the one from the ReportServer database. To get the path, query the Catalog table and use the value from the path field.

Debroahdebs answered 27/8, 2020 at 20:9 Comment(0)
H
0

the request failed with http status 401 unauthorized. ssrs 2008

from web.config add key="RS_UName" value="rajiv-pc" ---- incorrect

replace above value with your system name (rajiv) not sql server name like rajiv-pc

always there is system name not sql server name.

from web.config add key="RS_UName" value="rajiv" --- correct

Hindman answered 6/11, 2013 at 8:14 Comment(0)
E
0

curiousguy's answer solved my problem. thanks man!

Also, check your web.config. It must have must the following:

`

<system.web>
<httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
        validate="false" />
    </httpHandlers>
</system.web>
<system.webServer>
<handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd"
       type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, 
          PublicKeyToken=89845dcd8080cc91" />
</handlers>
  </system.webServer>

`

Public token must be the same otherwise it will blow another error.

Engaged answered 2/12, 2015 at 2:39 Comment(0)
B
0

Please just check the web service url you're pointing to. I deployed an SSRS on two separate server and one worked fine while the other threw this error "the request failed with http status 401 unauthorized."

So after a few hours I saw saw that I wasn't pointing to the web service url on my web.config. Example change on the web.config the report service url: http://weburl/ReportServer.

THIS WORKS!!!

Blueprint answered 14/11, 2019 at 12:58 Comment(0)
W
0

We had recently moved to a new server. The SSRS id that we used to access the reports in our winform app had expired and needed a password change.

That resolved the issue.

We also made that password not expire.... :-(

Wyrick answered 26/10, 2022 at 15:16 Comment(0)
E
0

In case it helps anyone who is trying to access the SSRS API with custom auth, make sure that you add the sqlAuthCookie cookie with the 'localhost' (or your SSRS server's domain) domain parameter. If you leave domain blank you will get 401.

ie:

public async Task<string> GetAllCatalogItemsHtml(string filter, string css = "")
    {
        CookieContainer cookieContainer = new CookieContainer();
        cookieContainer.Add(new Cookie("sqlAuthCookie", conn.sqlAuthCookie, "/", "localhost"));
        using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
        {
            using (client = new HttpClient(handler))
            {
                string resp = await client.GetAsync(string.Format("https://{0}/reports/api/v2.0/CatalogItems", conn.ServerUrl)).Result.Content.ReadAsStringAsync();
                CatalogItemResponse catalogItems = JsonConvert.DeserializeObject<CatalogItemResponse>(resp);
Enrika answered 20/5, 2023 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.