title: ADO.net is not closing TCP connections fast enough
body: <p>I'm running a multi-threaded operation that fetches data from a SQL Server database using <code>SqlConnection</code> and <code>Parallel.ForEach()</code> and following is happening:</p>
  
  <ul>
  <li>I wrap <code>SqlConnection</code> in a <code>using</code> statement so that the connection is properly disposed.</li>
  <li>My process consistently throws an <code>SqlException</code> wrapped in an <code>AggregateException</code> after running successfully for some time ("A network-related or instance-specific error occurred while establishing a connection to SQL Server..")</li>
  <li>I  found that this happens right around 2^14 (16384) calls to the database (in total, across all threads).  </li>
  <li>I fired up perfmon and I can see that that's also the number of TCP connections that are open right around the time that the exception is thrown ("Connections Established" counter).</li>
  <li>I'm certain that there's no connection leakage in my code - there are very few places where I am querying the database and they all properly dispose the connection (in fact, there is no other pattern I use for querying the database other than vanilla <code>using(...)</code>)</li>
  <li>I turned off the connection pool and the same behavior occurs.  </li>
  <li>Oddly, if I delete an index in SQL Server that makes my queries fast, the operation completes successfully (albeit very slowly) - no exception is thrown.  I observe that # of Connections Established rises linearly to about 13K and then stabilizes for some time, and then there's some periods with a linear decline, all while the operation is running.</li>
  <li>My conclusion is that with the index established, .net is processing data more quickly than it can close out the connections and eventually hits some kind of OS or .NET socket max threshold.  Without the index, .NET is still maintaining too many connections, but it has the time to close enough of them down so that the max open sockets threshold is not hit.</li>
  </ul>
  
  <p>I'm at a loss on how to instruct .NET to close-out those connections.  I thought that that happened auto-magically when the <code>SqlConnection</code> is disposed.</p>