【问题标题】:Unable to set Reporting Services Parameters无法设置 Reporting Services 参数
【发布时间】:2012-03-21 22:48:12
【问题描述】:

我正在从基于 ASP.NET (MVC) 的应用程序生成报告服务报告,但在设置报告参数时遇到问题。

我相信这个问题是在我们将 SQL Server 从 2005 升级到 2008 R2(以及 Reporting Services 以及它)之后才出现的。

遇到的原始错误来自调用 rsExec.Render:

过程或函数“pCommunication_ReturnRegistrationLetterDetails” 需要未提供的参数“@guid”。

调试代码我注意到 rsExec.SetExecutionParameters 返回以下响应:

无法调用 'NameOfApp.SQLRSExec.ReportExecutionService.SetExecutionParameters(NameOfApp.SQLRSExec.ParameterValue[], string)' 因为它是一个 web 方法。

这是完整的功能:

public static bool ProduceReportToFile(string reportname, string filename, string[,] reportparams, 
    string fileformat)
{
    bool successful = false;
    SQLRS.ReportingService2005 rs = new SQLRS.ReportingService2005();
    SQLRSExec.ReportExecutionService rsExec = new NameOfApp.SQLRSExec.ReportExecutionService();

    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Prepare Render arguments
    string historyID = null;
    string deviceInfo = null;

    // Prepare format - available options are "PDF","Word","CSV","TIFF","XML","EXCEL" 
    string format = fileformat;

    Byte[] results;
    string encoding = String.Empty;
    string mimeType = String.Empty;
    string extension = String.Empty;

    SQLRSExec.Warning[] warnings = null;
    string[] streamIDs = null;

    // Define variables needed for GetParameters() method
    // Get the report name
    string _reportName = reportname;
    string _historyID = null;
    bool _forRendering = false;
    SQLRS.ParameterValue[] _values = null;
    SQLRS.DataSourceCredentials[] _credentials = null;
    SQLRS.ReportParameter[] _parameters = null;

    // Get if any parameters needed.
    _parameters = rs.GetReportParameters(_reportName, _historyID,
                    _forRendering, _values, _credentials);

    // Load the selected report.
    SQLRSExec.ExecutionInfo ei =
            rsExec.LoadReport(_reportName, historyID);

    // Prepare report parameter.
    // Set the parameters for the report needed.
    SQLRSExec.ParameterValue[] parameters =
            new SQLRSExec.ParameterValue[1];

    // Place to include the parameter.
    if (_parameters.Length > 0)
    {
        for (int i = 0; i < _parameters.Length; i++)
        {
            parameters[i] = new SQLRSExec.ParameterValue();
            parameters[i].Label = reportparams[i,0];
            parameters[i].Name = reportparams[i, 0];
            parameters[i].Value = reportparams[i, 1];
        }
    }
    rsExec.SetExecutionParameters(parameters, "en-us");
    results = rsExec.Render(format, deviceInfo,
                out extension, out encoding,
                out mimeType, out warnings, out streamIDs);

    // Create a file stream and write the report to it
    using (FileStream stream = System.IO.File.OpenWrite(filename))
    {
        stream.Write(results, 0, results.Length);
    }
    successful = true;

    return successful;
}

任何想法为什么我现在无法设置参数?如果不需要参数,报告生成不会出现问题。

【问题讨论】:

    标签: web-services reporting-services ssrs-2008


    【解决方案1】:

    报告服务如何将参数传递给提供数据的存储过程似乎存在问题。正在将字符串 guid 传递给报告,并且存储过程需要 varchar guid。我怀疑报告服务可能已经注意到该字符串遵循 guid 格式模式,因此将其作为唯一标识符传递给存储过程。

    我将报告的数据源从“存储过程”更改为“文本”,并将 SQL 设置为“EXEC pMyStoredOProcName @guid”。

    请注意,作为字符串传递给存储过程的 guid 可能不是最佳实践...我只是在调试另一个开发人员代码的问题。

    【讨论】:

      【解决方案2】:

      参数_reportName 不能为空或为空。 [CLASSNAME].[METHODNAME]() 反射 API 无法创建并返回 SrsReportNameAttribute 对象

      在这种特定情况下,早期的完整编译似乎没有完成。

      如果你遇到这个问题,我建议你先编译错误信息中提到的类,看看是否能解决问题。

      1. 转到 AOT(按 Ctrl+D)

      2. 在类中查找 CLASSNAME

      3.编译(F7)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多