Web services 无法设置Reporting Services参数

Web services 无法设置Reporting Services参数,web-services,reporting-services,ssrs-2008,Web Services,Reporting Services,Ssrs 2008,我正在从基于ASP.NET(MVC)的应用程序生成reporting services报表,但在设置报表参数时遇到问题 我相信这个问题只是在我们将SQL Server从2005年升级到2008年R2(以及随之而来的Reporting Services)之后才出现的 调用rsExec.Render时遇到原始错误: 程序或功能“pCommunication\u ReturnRegistrationLetterDetails” 需要未提供的参数'@guid' 调试代码时,我注意到rsExec.SetE

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

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

调用rsExec.Render时遇到原始错误:

程序或功能“pCommunication\u ReturnRegistrationLetterDetails” 需要未提供的参数'@guid'

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

无法调用'NameOfApp.SQLRSExec.ReportExecutionService.SetExecutionParameters(NameOfApp.SQLRSExec.ParameterValue[], 字符串“”,因为它是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;
}
public static bool ProduceReportToFile(字符串reportname,字符串filename,字符串[,]reportparams,
字符串(文件格式)
{
bool成功=错误;
SQLRS.ReportingService2005 rs=新的SQLRS.ReportingService2005();
SQLRSExec.ReportExecutionService rsExec=app.SQLRSExec.ReportExecutionService()的新名称;
rs.Credentials=System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials=System.Net.CredentialCache.DefaultCredentials;
//准备呈现参数
字符串historyID=null;
字符串deviceInfo=null;
//准备格式-可用选项有“PDF”、“Word”、“CSV”、“TIFF”、“XML”、“EXCEL”
字符串格式=文件格式;
字节[]结果;
字符串编码=string.Empty;
string mimeType=string.Empty;
字符串扩展名=string.Empty;
SQLRSExec.Warning[]warnings=null;
字符串[]streamIDs=null;
//定义GetParameters()方法所需的变量
//获取报告名称
字符串_reportName=reportName;
字符串_historyID=null;
bool\u forRendering=false;
SQLRS.ParameterValue[]_values=null;
SQLRS.DataSourceCredentials[]\u credentials=null;
SQLRS.ReportParameter[]_parameters=null;
//如果需要任何参数,请获取。
_parameters=rs.GetReportParameters(_reportName,_historyID,
_对于呈现,_值,_凭证);
//加载所选报告。
SQLRSExec.ExecutionInfo ei=
rsExec.LoadReport(_reportName,historyID);
//准备报表参数。
//设置所需报告的参数。
SQLRSExec.ParameterValue[]参数=
新的SQLRSExec.ParameterValue[1];
//放置以包含参数。
如果(_parameters.Length>0)
{
对于(int i=0;i<_parameters.Length;i++)
{
parameters[i]=新的SQLRSExec.ParameterValue();
参数[i].Label=reportparams[i,0];
参数[i].Name=reportparams[i,0];
参数[i].Value=reportparams[i,1];
}
}
rsExec.SetExecutionParameters(参数“en-us”);
结果=rsExec.Render(格式,deviceInfo,
输出扩展,输出编码,
输出mimeType、输出警告、输出StreamID);
//创建文件流并将报告写入其中
使用(FileStream-stream=System.IO.File.OpenWrite(文件名))
{
stream.Write(results,0,results.Length);
}
成功=正确;
成功回归;
}

你知道为什么我现在不能设置参数吗?如果不需要参数,则报告生成不会出现问题。

看起来可能是reporting services如何将参数传递到提供数据的存储过程的问题。正在向报表传递字符串guid,存储过程需要varchar guid。我怀疑reporting services可能注意到字符串遵循guid格式模式,因此将其作为唯一标识符传递给存储过程

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


请注意,作为字符串传入存储过程的guid可能不是最佳做法。。。我只是用另一个开发人员代码调试了一个问题。

参数
\u reportName
不能为null或空。
[CLASSNAME].[METHODNAME]()
反射API无法创建并返回
srsrsreportnameattribute
对象

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

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

  • 转到AOT(获取Ctrl+D)

  • 在类中查找类名

  • 3.编译它(F7)