Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
The request failed with HTTP status 401: Unauthorized.
hi im trying to host my reports developed in sql2008 to reporting server.im getting the above error.
though these working locally im getting problem with credentials.
i tried in many ways but im not able to find the solution.
i tried to put following tag inside <system.web>

<identity impersonate="true" userName="SQL2008R2_" password="***"/>

if (!IsPostBack)
        {
            rptViewWeeksales.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            rptViewWeeksales.ServerReport.ReportServerUrl = new Uri("https://rs2k801.discountasp.net/ReportServer");//for local system:URL http://localhost:8080/Reportserver
            string strReport = @"/globalaviat/Reports/scm/rptweekSales";
            this.rptViewWeeksales.ServerReport.ReportPath = strReport;
            Microsoft.Reporting.WebForms.ReportParameter[] @territoryId = new Microsoft.Reporting.WebForms.ReportParameter[1];
            @territoryId[0] = new Microsoft.Reporting.WebForms.ReportParameter("territoryid", Session["territoryid"].ToString());
            rptViewWeeksales.ServerReport.SetParameters(@territoryId);
            rptViewWeeksales.ServerReport.Refresh();
        }



i configured properly while deploying to server like folder path,server url,datasource etc.
plz help me.
Posted
Updated 21-Jan-11 4:13am
v2
Comments
Dylan Morley 21-Jan-11 9:27am    
When you put in the following into your browser, you are prompted for uid + pwd

http://rs2k801.discountasp.net/ReportServer

If you put in valid credentials here, do you see the report server page OK?

Sorry, my bad - I forgot that was Read Only

You've got to set rptInventory.ServerReport.ReportServerCredentials

Have a look at this link, which explains in full how to do this (scroll down to the answer by H.Laasri)

http://int.social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/5aa7eee7-d4a7-427a-ab8d-7a3d4d4f0bf3[^]

C#
public partial class ReportViewerCredentials : IReportServerCredentials
    {
        private string _userName;
        private string _password;
        private string _domain;
        public ReportViewerCredentials(string userName, string password, string domain)
        {
            _userName = userName;
            _password = password;
            _domain = domain;
        }

        public WindowsIdentity ImpersonationUser
        {
            get
            {
                //return null;
                return WindowsIdentity.GetCurrent();
            }
        }
        public ICredentials NetworkCredentials
        {
            get
            {
                return new NetworkCredential(_userName, _password, _domain);
            }
        }
        public bool GetFormsCredentials(out Cookie authCookie,
                out string userName, out string password,
                out string authority)
        {
            authCookie = null;
            userName = _userName;
            password = _password;
            authority = _domain;
            // Not using form credentials
            return false;
        }
    }
protected void Page_Load(object sender, EventArgs e)
    {
        ShowReport();
    }
private void ShowReport()
    {
        try
        {
             ReportViewerCredentials rpCredentials = new ReportViewerCredentials(ConfigurationManager.AppSettings["ReportUser"], ConfigurationManager.AppSettings["ReportPassword"], ConfigurationManager.AppSettings["ReportDomain"]);
             ReportViewer1.ServerReport.ReportServerCredentials = rpCredentials;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
 
Share this answer
 
yes after giving credentials it is properly working on server side.
but when i try using my asp.net aspx page it is throwing the above error.

rptInventory.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;


ICredentials credentials = new NetworkCredential("xyzuser", "xyzpassword", "globalaviatech.com");



rptInventory.ServerReport.ReportServerUrl = new Uri("https://rs2k801.discountasp.net/ReportServer");
string strReport = @"/globalaviat/Reports/scm/SalesOfTerritory";
this.rptInventory.ServerReport.ReportPath = strReport;
Microsoft.Reporting.WebForms.ReportParameter[] @territoryid = new Microsoft.Reporting.WebForms.ReportParameter[1];
@territoryid[0] = new Microsoft.Reporting.WebForms.ReportParameter("territoryid", Session["territoryid"].ToString());
rptInventory.ServerReport.SetParameters(@territoryid);
rptInventory.ServerReport.Refresh();
}
 
Share this answer
 
Comments
Sandeep Mewara 21-Jan-11 10:04am    
Not an answer. Either use comment feature or update your question from next time.
You don't seem to have set the credentials to the ServerReport

e.g.

rptInventory.ServerReport.ReportServerCredentials = credentials;


http://www.devx.com/dotnet/Article/30424/1763/page/3[^]
 
Share this answer
 
v2
Comments
Sandeep Mewara 21-Jan-11 10:04am    
Comment from OP:
Hi Morley thankz a lot for quick reply.
can u plz let me know which namspace should i mention to recognize this.
i gave
using System.Net;
and more????which namespace

rptInventory.ServerReport.ReportServerCredentials.NetworkCredentials = credentials;
Property or indexer Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentiacannot be assigned to --
it is read only C:\Documents and Settings\admin\Desktop\aspproject-14dec\Reports\PurchasedProducts.aspx.cs
im getting following error.
 
Share this answer
 
Comments
Dylan Morley 21-Jan-11 10:12am    
See my updated answer

PS: Use the comments feature to add more information, don't use 'Post Answer'
Member 4306138 21-Jan-11 10:35am    
hi please can u clear my error.
for above
using System.Net; and more????which namespace rptInventory.ServerReport.ReportServerCredentials.NetworkCredentials = credentials;


Property or indexer Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentiacannot be assigned to --
it is read only
im getting following error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900