I have an application that should connect to a SQL Server running on a remote server using a named instance.
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.
var context = serviceScope.ServiceProvider.GetService<AppContext>();
context.Users.ToList();
In the debugger it never reaches the exception handler.
Instead I see a lot of output like this:
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).
Using node.js I can connect to the SQL Server even from docker without problem.
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.
- works using IISExpress (so runs on Windows)
- 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)
- 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)
- 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
Connecting string:
"Data Source=remoteIP\\WEBDB;Initial Catalog=TestDB;User ID=testuser;Password=******;"
Also tried with "Integrated Security=False;" in the connection string
Server Authentication is set to mixed
I can reproduce this is also without Entity Framework:
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}");
}
It will hang on the line conn.Open();.
Any idea what I could do?
Update:
- entered connection string incorrectly.
- updated code with complete example
Edit
This works:
var conString = "Data Source=10.0.75.1,1433;Initial Catalog=TestDB;Integrated Security=False;User ID=testuser;Password=********";
This doesn't work:
var conString = "Data Source=10.0.75.1\\Developer;Initial Catalog=TestDB;Integrated Security=False;User ID=testuser;Password=********";
I can ping the remote IP address and also the remote server name.
Unfortunately installing mssql-cli on the ubuntu image fails because of missing dependencies.

