how to open ssrs report from asp web page using report viewer

淺唱寂寞╮ 提交于 2019-12-04 10:40:24

问题


I'm trying to open an ssrs report on my web pages using ReportViewer. For the Report Serverl URL I have:

http://db_servers/ReportsServer_SENSORSQLSERVER

and for my report path I have:

http://db_servers/ReportsServer_SENSORSQLSERVER/Pages/ReportViewer.aspx?%2fCustomer1&rs:Command=Render.

I have looked through many sites and tutorial on how to add URL but I still get an error saying: The length of my link must be below 260 characters long. (rsInvalidItemPath). I also want to mention that my report server is in Native mode. My report server is located in another computer so I made sure the processing mode on my report viewer is remote. Whenever I go to the surver url I can clearly see the list of my reports and when I click on a report I can see it as well so I know my urls are correct. I have tried including a slash in front of my report path url, replacing "2%f" with a space. Nothing seems to work. Any idea? Thanks.


回答1:


You need to separate out the URL to the server, report path and add the parameters to a parameters array.

Here's a sample:

    protected void Page_Init(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        // Set the processing mode for the ReportViewer to Remote
        reportViewer.ProcessingMode = ProcessingMode.Remote;

        ServerReport serverReport = reportViewer.ServerReport;

        // Set the report server URL and report path
        serverReport.ReportServerUrl =
            new Uri("http://<Server Name>/reportserver");
        serverReport.ReportPath =
            "/AdventureWorks Sample Reports/Sales Order Detail";

        // Create the sales order number report parameter
        ReportParameter salesOrderNumber = new ReportParameter();
        salesOrderNumber.Name = "SalesOrderNumber";
        salesOrderNumber.Values.Add("SO43661");

        // Set the report parameters for the report
        reportViewer.ServerReport.SetParameters(
            new ReportParameter[] { salesOrderNumber });
    }
}

Above taken from Using the WebForms ReportViewer Control.




回答2:


You should replace the "2%f" by "/".

The problem is with your ReportPath property, e.g:

%2fCustomer1 -> /Customer1




回答3:


Very simple method to open SSRS :

                string reportName = "TestReport";
                string displayName = reportName;
                bool isDomainAuthentication = false;

                var reportParameters = new List<ReportParameter>();
                reportParameters.AddRange((List<ReportParameter>)Session["ReportParameters"]);

                string ReportServerURL = "http://DESKTOP38/ReportServer_SQLEXPRESS";
                reportViewer1.ServerReport.ReportServerUrl = new Uri(ReportServerURL);
                reportViewer1.ServerReport.ReportPath = "FolderName" + reportName;
                reportViewer1.ServerReport.DisplayName = displayName;
                reportViewer1.ShowPrintButton = true;
                reportViewer1.ShowToolBar = true;
                reportViewer1.ShowCredentialPrompts = false;

                if (!isDomainAuthentication)
                {
                    string userId = "DESKTOP38"; //Username
                    string password = "test";
                    string domain = ReportServerURL;

                    IReportServerCredentials reportCredentials = new ReportServerCredentials(userId, password, domain);
                    reportViewer1.ServerReport.ReportServerCredentials = reportCredentials;
                }
                if (reportParameters != null)
                {
                    reportViewer1.ServerReport.SetParameters(reportParameters);
                }
                this.reportViewer1.ServerReport.Refresh();


来源:https://stackoverflow.com/questions/12607920/how-to-open-ssrs-report-from-asp-web-page-using-report-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!