title: Difference between Open and OpenAsync (SqlConnection)
body: <p>(The title looks similar to <a href="https://stackoverflow.com/questions/40662788/sqlconnection-open-vs-sqlconnection-openasync-whats-different-between-the-two?rq=1">SqlConnection.Open vs SqlConnection.OpenAsync - what&#39;s different between the two beyond the obvious?</a> but a. It doesn't has any answer, and b. the observations in my case are different)</p>
  
  <p>While bench-marking to chase a performance issue in an asp.net service, I accidentally hit a queer observation where <code>SqlConnection.Open</code> performs far better than <code>SqlConnection.OpenAsync</code>(more details below).</p>
  
  <p>From the source code <a href="https://referencesource.microsoft.com/#System.Data/System/Data/SqlClient/SqlConnection.cs,48932d2b804ed473" rel="nofollow noreferrer">here</a> looks like the code of <code>Open</code> is just a subset of <code>OpenAsync</code>. Diff <a href="https://www.diffchecker.com/QIIgyHMa" rel="nofollow noreferrer">here</a></p>
  
  <p>I am curious on given <code>Open</code> does exactly same things as <code>OpenAsync</code>, what is the advantage of using the async version(if any)?</p>
  
  <p><strong>Details:</strong></p>
  
  <p>This is how I create the connection</p>
  
  <pre><code>using (SqlConnection connection = new SqlConnection(connectionString))
  {
      await connection.OpenAsync();
      // run actual operation on connection (in an async way)
  }
  </code></pre>
  
  <p>This code block takes 
  <code>13 seconds on an average for 100 concurrent calls</code>. I have tried increasing the thread pool count to 200 to reduce chances of <code>tasks</code> waiting for threads. The observation doesn't change even after letting the default threadpool count.</p>
  
  <p>The interesting part is if I change <code>await connection.OpenAsync()</code> with <code>connection.Open()</code> the performance improves 10 times.
  <code>1.01 seconds on an average of 100 concurrent calls</code>.  </p>
  
  <p>I tried playing around with <code>connection pool settings</code> and looks like even if I reduce it to an arbitrarily low number (2 is what tested with) the number doesn't change much.</p>
  
  <p>The driver code is:</p>
  
  <pre><code>Task.WhenAll(Enumerable.Range(0, maxConcurrentCalls).Select((idx) =&gt; CallQuery(idx))).Result;
  </code></pre>
  
  <p>The reason I do a wait (by doing a <code>.Result</code> is because the driver code is a console app which has to have a sync <code>main</code>). In the actual production code everything including the controller is <code>async</code>.</p>