title: SqlCommand maximum parameters exception at 2099 parameters
body: <p>I am batching different queries in one SqlCommand stopping the queries batch when I hit the 2100 parameter limit. If my batch has 2100 or 2099 parameters I still get the exception.</p>
  
  <p>The following test code throws 'too many parameters exception' even if the number of parameters is less than 2100.</p>
  
  <pre><code>var parametersMax = 2099;
  
  var connection = new SqlConnection(@"Data Source=.;Integrated Security=SSPI;");
  connection.Open();
  
  var enumerable = Enumerable.Range(0, parametersMax);
  
  var query = string.Format("SELECT {0}", String.Join(", ", enumerable.Select(s =&gt; string.Format("P{0} = @p{0}",s))));
  
  var command = new SqlCommand(query, connection);
  
  foreach(var i in enumerable)
      command.Parameters.Add(string.Format("p{0}",i), i);
  
  // here: command.Parameters.Count is 2099
  
  var reader = command.ExecuteReader(); // throws: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.
  </code></pre>
  
  <p>Considering the exception message and the documentation here: <a href="http://msdn.microsoft.com/en-us/library/ms143432.aspx">http://msdn.microsoft.com/en-us/library/ms143432.aspx</a> I was expecting to be able to have 2100 parameters in one query, but this doesn't seem to be true. Does anyone know why? Am I missing something?</p>
  
  <p>(I am using Sql Server 2008 R2)</p>