为什么我收到此错误{"由于对象的当前状态,操作无效。"} C#

时间:2017-02-03 17:49:08

标签: c# asp.net reporting-services

我已经制作了一份SSRS报告,该报告以计数数据和费用数据的形式汇总了我的数据。我显示此数据的文本框具有操作设置,可使用从摘要报告传递的参数打开更详细的报告。在SSRS服务器上查看时,这些报告可以根据需要运行。

现在我有一个使用C#管理这些报告的数据输入的Web应用程序,我使用aspx ReportViewer在应用程序中显示这些报告。问题是如果我从我的C#Web应用程序打开摘要报告,然后单击链接打开屏幕更改的详细报告,看起来它将打开详细报告,但它只是坐在那里并且不会呈现报告。

当我在LocalHost上从Visual Studios运行应用程序时,当我尝试打开摘要报告时,我收到此错误消息; {"由于对象的当前状态,操作无效。"}

以下是我正在使用的C#代码:

 protected void Page_Load(object sender, EventArgs e)
{
    //Get the report server url from web.config
    String reportServerUrl = ConfigurationManager.AppSettings.Get("ReportServerUrl");
    ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(reportServerUrl);

    String report = Request.QueryString["r"];
    if (report == "TransportTotals")
    {
        ReportViewer1.ServerReport.ReportPath = "/ExTraReports/TransportTotals";
        this.Title = "Transport Totals Report";
    }

任何人都可以解释报告出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

我能够解决问题。更正后的代码如下:

String report = Request.QueryString["r"];
    if (report == "TransportTotals" && ReportViewer1.ServerReport.ReportPath != "/ExTraReports/NEWClosedTransportsByStateAndAgencyTypeAndNameDetail")
    {
        ReportViewer1.ServerReport.ReportPath = "/ExTraReports/TransportTotals";
        this.Title = "Transport Totals Report";
    }

我必须检查每次页面加载时返回的报告路径,看看我们是否正在调用具有不同路径的详细报告。如果是这样它然后使if块失败并打开链接的报告。