title: A network-releated or instance-specific error occurred while establishing a connection to SQL Server
body: <p>I have a simple mvc web site (using the VS internet template) on azurewebsites talking to a SQL Azure database in the same data center.  The database at this time is just to do the built-in SimpleMembership Provider.  I have already switched from the default App_Data mdf file to Azure SQL.  It works fine, but sometimes after a while, it would give:</p>
  
  <blockquote>
    <p>A network-related or instance-specific error occurred while
    establishing a connection to SQL Server. The server was not found or
    was not accessible. Verify that the instance name is correct and that
    SQL Server is configured to allow remote connections. (provider: SQL
    Network Interfaces, error: 26 - Error Locating Server/Instance
    Specified)</p>
  </blockquote>
  
  <p>with a long message:</p>
  
  <blockquote>
    <p><strong>SQLExpress database file auto-creation error:</strong> </p>
    
    <p>The connection string specifies a local Sql Server Express instance
    using a database location within the application's App_Data directory.
    The provider attempted to automatically create the application
    services database because the provider determined that the database
    does not exist. The following configuration requirements are necessary
    to successfully check for existence of the application services
    database and automatically create the application services database:</p>
  </blockquote>
  
  <p>But I do <em>not</em> have a connection string using SQL Server Express!</p>
  
  <p>Restarting the web site immediately does not remove the error.</p>
  
  <p>Without changing anything and restarting the web site 15 minutes later give:</p>
  
  <blockquote>
    <p><strong>502 - Web server received an invalid response while acting as a
    gateway or proxy server.</strong></p>
    
    <p>There is a problem with the page you are looking for, and it cannot be
    displayed. When the Web server (while acting as a gateway or proxy)
    contacted the upstream content server, it received an invalid response
    from the content server.</p>
  </blockquote>
  
  <p>Previously, I could restore the website back to working order by just re-publshing from VS.  But for the last hour I have tried and tried and I cannot get the web site to work again.</p>
  
  <p><strong>What is the problem about SQL Server Express really about?</strong></p>
  
  <p>My connection string section contains:</p>
  
  <pre><code>&lt;connectionStrings&gt;
    &lt;add name="DefaultConnection" connectionString="Server=tcp:sabl6h4---.database.windows.net,1433;Database=MVC;User ID=test@sabl6h4---;Password=----;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" /&gt;
    &lt;add name="Entities" connectionString="metadata=res://*/Data.Model1.csdl|res://*/Data.Model1.ssdl|res://*/Data.Model1.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=sabl6h4---.database.windows.net;initial catalog=MVC;user id=test;password=----;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
   &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Just to be sure, I copied and pasted sabl6h4---.database.windows.net into SSMS and connected using login test and it opened the database without problem.</p>
  
  <hr>
  
  <p><strong>One day later</strong>:  I created a new azurewebsite and published the exact same project and same web.config.  It works fine without problems.  After some minutes, the exact same error occurred!</p>
  
  <hr>
  
  <p><strong>Three more hours later</strong>: Went for lunch, came back, hit the browser Refresh button, and the web site is up again. I am convinced that someone is fooling around with the settings at the back end.</p>