如何解决错误:此报告需要报告参数“*”的默认值或用户定义值

时间:2009-06-15 15:30:57

标签: c# sql-server reporting-services

我收到了错误:

This report requires a default or user-defined value for the report parameter '*'. To run or subscribe to this report, you must provide a parameter value.

即使正在填充值'*',

偶尔会从我的报告服务器中出现。任何可以让我追踪它的想法或线索?一些观点。

  • 我以异步方式运行报告(意味着4个线程一次生成报告)。
  • 报告提供了2个参数(始终提供)和一个派生参数。
  • 我每个会话运行1,000个报告,每个线程约250个报告。
  • 有时错误会在几秒钟后发生,有时会在数小时后发生。

    using System;
    using System.Globalization;
    using System.IO;
    using Cns.ReportExecution2005;
    
    public class PdfGenerator
    {
        private readonly ReportExecutionService reportExecutionService;
        public PdfGenerator(string executionServiceAddress)
        {
            // Create a new proxy to the web service
            this.reportExecutionService = new ReportExecutionService
                                              {
                                                  Credentials = System.Net.CredentialCache.DefaultNetworkCredentials,
                                                  Url = executionServiceAddress
                                              };
        }
        public Stream GenerateReport(string reportName, string format, ReportGeneratorParameter[] parameters)
        {
            if (reportName == null)
            {
                throw new ArgumentNullException("reportName");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            this.reportExecutionService.LoadReport(reportName, null);
            if (parameters != null)
            {
                var executionParameters = new ParameterValue[parameters.Length];
                for (int i = 0; i < parameters.Length; ++i)
                {
                    executionParameters[i] = new ParameterValue
                    {
                        Label = parameters[i].Name,
                        Name = parameters[i].Name,
                        Value = Convert.ToString(parameters[i].Value, CultureInfo.InvariantCulture)
                    };
                }
                this.reportExecutionService.SetExecutionParameters(executionParameters, "en-us");
            }
            string extension;
            string encoding;
            string mimeType;
            Warning[] warnings;
            string[] streamIDs;
            byte[] results = this.reportExecutionService.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
            return new MemoryStream(results);
        }
    }
    

4 个答案:

答案 0 :(得分:7)

对于寻找此主题答案的其他人(谷歌搜索带我到这里),也可能是由参数定义为“从查询”而不是“非查询”引起的。然后,如果传入的参数根据查询无效,则可能会出现此错误。 例如,您有一个名为CustomerId的参数,该参数通过Web界面显示为Select CustomerId,CustomerName from Customer 假设数据库中有效的客户ID为1到10。 如果在c#中传入一个值为24的参数,(即超出该范围)RS就像从未传入参数一样,因为它检测到它不在有效范围内。 希望这有帮助

答案 1 :(得分:4)

使用外部Web服务时,重要的是要意识到通过自动生成的包装器类的实例发出的每个请求都与通过该实例进行的所有其他调用相关联。所以这里有一个PdfGenerator类被实例化,但是调用它的四个线程正在通过相同的接口创建它们,所以你有:{/ p>

  

线程A:设置参数
  线程B:设置参数
  线程A:执行(消耗线程B的参数)
  线程B:执行(没有给出参数,抛出异常)

每个线程都需要自己的PdfGenerator类实例,因为每个线程都需要自己的ReportExecutionService实例

答案 2 :(得分:1)

偶然发现了这个问题:我的情况比较简单(没有多线程,一个报告),但我得到了同样的信息。

我有两个版本的查找表,它们的同步性很差(另一个帖子的主题)。此报告的其中一个参数是查找此表中的值。由于尚未发生同步,基本上我传递的参数没有相应的值。我回来的错误信息是,当我真的提供了一个“坏”参数时,我没有提供参数。令人沮丧。

答案 3 :(得分:1)

在我的情况下,问题是可用的值在值的末尾有额外的空格,所以'ABC001'不等于查询'ABC001'的值,所以它是一个无效的值,它的作用就好像我从未发送参数一点都不我进入了构建可用值并进行修剪的查询..故事的道德......总是修剪!洛尔。