C# 此 RPC 请求中提供的参数过多。最大是2100。?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1028547/
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:54:20  来源:igfitidea点击:

Too many parameters were provided in this RPC request. The maximum is 2100.?

c#.netsql-serveribatis.net

提问by DevelopingChris

A search query returned this error. I have a feeling its because the in clause is ginormous on a subordinant object, when I'm trying to ORM the other object.

搜索查询返回了此错误。我有一种感觉,因为当我试图 ORM 另一个对象时,in 子句在一个从属对象上是巨大的。

Apparently in clauses shouldn't be built 1 parameter at a time. Thanks ibatis.

显然,在子句中不应一次构建 1 个参数。谢谢伊比斯。

采纳答案by JP Alioto

Your best bet is to revise your application to pass less than 2100 parameters to the stored procedure. This is a DBMS limit that can't be raised.

最好的办法是修改应用程序,将少于 2100 个参数传递给存储过程。这是无法提高DBMS 限制

回答by Aaron Alton

You can do a few things:

你可以做几件事:

  1. Pump the params into a temp table and use said temp table to filter your query. See https://stackoverflow.com/a/9947259/37055
  2. Create a comma-delimited array, and pass the array into SQL Server as a varchar(x). Split it out via TSQL (here are a few methods) and use the resulting rowset to filter your search results.
  3. Have a look at your application logic. It's more than a little strange to be passing 2100 parameters to a stored procedure.
  1. 将参数泵入临时表并使用所述临时表来过滤您的查询。见https://stackoverflow.com/a/9947259/37055
  2. 创建一个逗号分隔的数组,并将该数组作为 varchar(x) 传递到 SQL Server。通过 TSQL 将其拆分(这里有一些方法)并使用生成的行集来过滤搜索结果。
  3. 看看你的应用程序逻辑。将 2100 个参数传递给存储过程有点奇怪。

回答by Mark Brittingham

If you are passing 2100 parameters to a single stored procedure, you are simply doing something wrong. Don't raise the limit or try to work around this abomination, figure out how to do things right.

如果您将 2100 个参数传递给单个存储过程,那么您只是做错了什么。不要提高限制或试图解决这个可憎的问题,弄清楚如何正确地做事。

回答by Konamiman

I got this same error when using an apparently innocent LINQ to SQL query. I just wanted to retrieve all the records whose ids were amongst the ones stored in an array:

使用明显无害的 LINQ to SQL 查询时,我遇到了同样的错误。我只想检索其 id 位于存储在数组中的所有记录:

dataContext.MyTable.Where(item => ids.Contains(item.Id)).ToArray();

It turned out that the ids array had more than 2100 items, and it seems that the DataContext adds one parameter for each item in the array in the resulting SQL query.

结果发现 ids 数组有 2100 多个项目,而且 DataContext 似乎在生成的 SQL 查询中为数组中的每个项目添加了一个参数。

At the end it was a bug in my code, since the ids array had not to have so many items. But anyway it is worth to keep in mind that some extra validation is needed when using such constructs in LINQ to SQL.

最后它是我代码中的一个错误,因为 ids 数组不必有这么多项目。但无论如何值得记住,在 LINQ to SQL 中使用此类构造时需要一些额外的验证。