title: Pre-login handshake woes with connecting directly to SQL Azure
body: <p>We are currently experiencing a rather troublesome problem in our development environment with the following message...</p>
  
  <pre><code>A connection was successfully established with the server, 
  but then an error occurred during the pre-login handshake. 
  (provider: SSL Provider, error: 0 - The certificate's CN 
  name does not match the passed value.)
  </code></pre>
  
  <p>...the commonly accepted wisdom to resolving this problem is to set the <em>TrustServerCertificate</em> portion of the connection to <em>True</em>.  However, this does not work reliably or consistently.</p>
  
  <p>This particular error occurs in a number of instances, for instance testing our WCF Service in our Azure Emulator talking to live / hosted SQL Azure Instance or even using SQL Management Studio.  The only common denominator we've found is that this occurs only when we connect directly to SQL Azure as opposed to when its hosted and Azure is talking directly to SQL Azure (which does work).</p>
  
  <p>I've tried a number of tactics to resolve the problem (such as the one detailed <a href="http://www.wadewegner.com/2010/08/using-the-trustservercertificate-property-with-sql-azure-and-entity-framework/" rel="noreferrer">here</a>), i.e. believing it was connection related and removing pooling and other modifications to the connection string.  But alas, none are conclusive and more irritating is that the error is intermittent and will prevent access for a short period of time before magically resolving itself.  </p>
  
  <p>Other factors that I've eliminated.</p>
  
  <ul>
  <li>We're using the Transcient Application Block to attempt to recover from these errors, but no.</li>
  <li>Our office has no proxy server with our connection to the Azure hosted services.</li>
  </ul>
  
  <p>Has anyone else experienced this problem or has any suggestions?</p>