解決するThe maximum is 2100.

1187 ワード

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コンポーネントで定義されているさまざまなオブジェクトの最大サイズと最大数を指定します.Microsoftリンクを参照してください.https://docs.microsoft.com/zh-cn/sql/sql-server/maximum-capacity-specifications-for-sql-server?view=sql-server-2017
ユーザ定義関数パラメータの個数は最大2100
解決策
最大容量仕様を超えることができない以上、最大容量を超えることは避け、2100を超えるとロット更新を行えばよい.
コードは次のとおりです.
public void Test(IList 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