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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/996775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:09:59  来源:igfitidea点击:

How to solve error: This report requires a default or user-defined value for the report parameter '*'

c#sql-serverreporting-services

提问by Orion Adrian

I'm getting the error:

我收到错误:

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.

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.

very occasionally from my reporting server even when the value '*' is being populated. Any ideas or leads that might allow me to track it down? Some points.

即使在填充值 '*' 时,我的报告服务器也偶尔会出现这种情况。有什么想法或线索可以让我追踪它吗?几点。

  • I run the reports 4-way asynchronously (meaning 4 threads generating reports at a time).
  • The reports have 2 provided parameters (always supplied) and one derived parameter.
  • I run 1,000 reports per session with ~250 reports per thread.
  • Sometimes the error will hit after a few seconds, sometimes after many hours.

    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 路异步方式运行报告(意味着 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);
        }
    }
    

采纳答案by Orion Adrian

When working with external web services it's important to realize that each request made through an instance of automatically generated wrapper class is tied to all other calls made through that instance. So here one PdfGeneratorclass is being instantiated, but the four threads that are making calls to it are making them all through the same interface so that you have:

在使用外部 Web 服务时,重要的是要意识到通过自动生成的包装类的实例发出的每个请求都与通过该实例发出的所有其他调用相关联。因此,这里PdfGenerator正在实例化一个类,但是调用它的四个线程通过相同的接口调用它们,因此您拥有:

Thread A: Setup Parameters
Thread B: Setup Parameters
Thread A: Execute (consuming thread B's parameters)
Thread B: Execute (no parameters given, exception thrown)

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

Each thread will need its own instance of the PdfGeneratorclass in that each one needs its own instance of the ReportExecutionService

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

回答by Adam Tuliper - MSFT

For others looking for answers on this subject (google search brought me here) it can also be caused by a parameter being defined as "From Query" rather than "Non Queried". Then if you pass in a parameter that is not valid as per the query, you can get this error. For instance, you have a parameter called CustomerId which is presented via the web interface as Select CustomerId, CustomerName from Customer Lets say valid customer ids in the database are 1 to 10. If you pass in a parameter in c# with a value of 24, (Ie out of that range) RS acts as if the parameter was never passed in since it detects it is not in the valid range. hope this helps

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

回答by nick

Stumbled across this question: my situation is simpler (no multi-threading, one report), but I was getting the same message.

偶然发现这个问题:我的情况更简单(没有多线程,一份报告),但我收到了相同的消息。

I have two versions of a lookup table that are poorly synchronized (topic for another post). One of the parameters for this report is looking for values from this table. As the synchronization had not occurred yet, basically I was passing a parameter with no corresponding value. The error message I was getting back was that I had not supplied a parameter when, really, I had supplied a "bad" parameter. Frustrating.

我有两个版本不同步的查找表(另一篇文章的主题)。此报告的参数之一是从该表中查找值。由于同步还没有发生,基本上我传递了一个没有对应值的参数。我得到的错误消息是我没有提供参数,而实际上,我提供了一个“坏”参数。令人沮丧。

回答by Hugo

In my case the problem was the available values had extra spaces at end of value so 'ABC001' did not equal the value from the query 'ABC001 ' so it was an invalid value and it acted as if i never sent the parameter at all. I went into the query that build the available values and trimmed.. so moral of the story... always trim! lol.

在我的例子中,问题是可用值在值的末尾有额外的空格,所以 'ABC001' 不等于查询 'ABC001' 中的值,所以它是一个无效值,它表现得好像我从来没有发送过参数一样。我进入了构建可用值的查询并进行了修剪……故事的寓意……总是修剪!哈哈。