title: Can't connect to my SQL Server Express from an ASP.NET web app
body: <p>I'm working on a tool that uses an SQL Server as a database.</p>
  
  <p>First I was using Visual Studio's localdb, then I was using an Azure SQL Server, both of which worked just fine.</p>
  
  <p>I now tried to host my own SQL Server Express, but I can't seem to connect to it. It's hosted in an Azure VM, I have restarted it, enabled TCP and I have opened Port 1433 in Azure.</p>
  
  <p>I have tried both connecting remotely, running the web-app on my local computer and connecting to <code>tcp:{IP}\InstanceName</code>, as well as running the app on an IIS Server on my VM using <code>.\InstanceName</code> in the connection string (although I still get told to check if the server is set up correctly to handle TCP ? )</p>
  
  <p>Connecting locally on the VM, using Microsoft SQL Server Management Studio works though, so I suspect the connection string in my <code>web.config</code> must be wrong ... </p>
  
  <p>It looks like this: </p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="defaultConnection" 
           connectionString="Server=tcp:12.345.678.910\InstanceName,1433;Initial Catalog=master;Persist Security Info=False;User ID=sa;Password={mypassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" 
           providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>The error message I get is:</p>
  
  <blockquote>
    <p>Server Error in '/application-name' Application. The remote computer refused the network connection.</p>
    
    <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>
    
    <p>Exception Details: System.ComponentModel.Win32Exception: The remote computer refused the network connection</p>
    
    <p>Source Error:</p>
    
    <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p>
    
    <p>Stack Trace: [Win32Exception (0x80004005): The remote computer refused
    the network connection]</p>
    
    <p>[SqlException (0x80131904): 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: TCP Provider, error: 0 - The remote computer refused the network connection.)]    </p>
  </blockquote>
  
  <p><em>(and more but it doesn't seem important - will post if necessary or helpful)</em></p>
  
  <p>Any idea what I'm doing wrong?</p>