2012-03-21 75 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)