2012-03-21 72 views
0

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

我相信这个问题只发生在我们将SQL Server从2005升级到2008 R2(和Reporting Services)之后。

遇到的原始误差为从主叫rsExec.Render:

过程或函数 'pCommunication_ReturnRegistrationLetterDetails' 预计参数 '@guid',但未提供。

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

不能称之为 'NameOfApp.SQLRSExec.ReportExecutionService.SetExecutionParameters(NameOfApp.SQLRSExec.ParameterValue [], 字符串)'因为它是一种网络方法。

这里是它的全部功能:

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; 
} 

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

回答

0

看起来它可能是一个问题,报告服务如何将参数传递给提供数据的存储过程。一个字符串guid被传递给报告,存储过程需要一个varchar guid。我怀疑报告服务可能注意到遵循guid格式模式的字符串,因此将其作为uniqueidentifier传递给存储过程。

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

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

0

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

在这种特定情况下,它看起来像以前的完整编译没有完成。

如果遇到此问题,我建议您首先编译错误消息中提到的类,看看是否可以解决问题。

  1. 去AOT(获得按Ctrl + d)

  2. 在班

    找到CLASSNAME

3.compile它(F7)