title: Can't connect to SQL Server named instance from ASP.NET Core running in Docker (Linux)
body: <p>I have an application that should connect to a SQL Server running on a remote server using a named instance.</p>
  
  <p>Using IISExpress, I can connect to the SQL Server, but from Docker (Linux container) it fails - when accessing the context it just hangs - no exception or error message is thrown. E.g.</p>
  
  <pre><code>var context = serviceScope.ServiceProvider.GetService&lt;AppContext&gt;();
  context.Users.ToList();
  </code></pre>
  
  <p>In the debugger it never reaches the exception handler.</p>
  
  <p>Instead I see a lot of output like this:</p>
  
  <pre><code>The thread 125 has exited with code 0 (0x0).
  The thread 164 has exited with code 0 (0x0).
  The thread 0xa4 has exited with code 0 (0x0).
  </code></pre>
  
  <p>Using node.js I can connect to the SQL Server even from docker without problem. </p>
  
  <p>I can connect to a SQL Server Developer edition running on the same machine as Docker from ASP.NET Core in Docker when I use e.g. [ipaddress or host.docker.internal],1433 - unfortunately on the remote SQL Server, I cannot configure a fixed port.</p>
  
  <ul>
  <li>works using IISExpress (so runs on Windows)</li>
  <li>works when connecting to a SQL Server running on the dev machine when using a fixed port instead of named instance (but I can't change our production server)</li>
  <li>works when using node.js! from docker also with named instance (both: with hostname or ip address - so I can resolve remote names, firewall is not an issue)</li>
  <li>tried ASP.NET Core 2.2 and 3.0preview5 using Microsoft container as a base e.g. FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base</li>
  </ul>
  
  <p>Connecting string:</p>
  
  <pre><code>"Data Source=remoteIP\\WEBDB;Initial Catalog=TestDB;User ID=testuser;Password=******;"
  </code></pre>
  
  <p>Also tried with "Integrated Security=False;" in the connection string</p>
  
  <p>Server Authentication is set to mixed</p>
  
  <p>I can reproduce this is also without Entity Framework:</p>
  
  <pre><code>var conString = "Data Source=remoteIP\\WEBDB;Initial Catalog=TestDB;Integrated Security=False;User ID=testuser;Password=********";
  
  using (SqlConnection conn = new SqlConnection(conString))
  using (SqlCommand cmd = new SqlCommand("SELECT * FROM Users", conn))
  {
     conn.Open();
     var rows = cmd.ExecuteNonQuery();
     Console.WriteLine($"rows: {rows}");
  }
  </code></pre>
  
  <p>It will hang on the line <code>conn.Open();</code>.</p>
  
  <p>Any idea what I could do?</p>
  
  <p>Update:</p>
  
  <ul>
  <li>entered connection string incorrectly.</li>
  <li>updated code with complete example</li>
  </ul>
  
  <p><strong>Edit</strong></p>
  
  <p>This works:</p>
  
  <pre><code>var conString = "Data Source=10.0.75.1,1433;Initial Catalog=TestDB;Integrated Security=False;User ID=testuser;Password=********";
  </code></pre>
  
  <p>This doesn't work:</p>
  
  <pre><code>var conString = "Data Source=10.0.75.1\\Developer;Initial Catalog=TestDB;Integrated Security=False;User ID=testuser;Password=********";
  </code></pre>
  
  <p>I can ping the remote IP address and also the remote server name.</p>
  
  <p>Unfortunately installing mssql-cli on the ubuntu image fails because of missing dependencies. </p>