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

在使用SQL操作数据表时,如果用户定义的函数参数超过2100条会报错,

The incoming tabular data stream(TDS) remote procedure call (RPC) protocol stream is incorrect.Too many parameters provided in the RPC request.The maximum is 2100

这个原因是超过了SQL Server 的最大容量规范

指定 SQL Server 组件中定义的各种对象的最大大小和最大数量参考微软链接:https://docs.microsoft.com/zh-cn/sql/sql-server/maximum-capacity-specifications-for-sql-server?view=sql-server-2017

4624570-4e562e9ba8173153.png
用户定义的函数参数个数最大为2100

解决方法

既然不能超过最大容量规范,只能避免超过最大容量了,超过2100的话进行批次更新即可。

代码如下:

public void Test(IList<int> animalIds)
{
  using (var db = new SqlConnection(this.connectionString))
  {
    db.Open();
    while (animalIds.Any())
    {
       //一次插入1000条
      var ids2Insert = animalIds.Take(1000);
      animalIds = animalIds.Skip(1000).ToList();
      db.Execute(SQL,
        new
        {
            id = ids2Insert
        });
    }
  }
}

测试:

var ids = Test(Enumerable.Range(1, 2500).ToList());

Reference:
https://stackoverflow.com/questions/39592340/how-can-i-use-more-than-2100-values-in-an-in-clause-using-dapper

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值