.NET Core 3.0 Docker Container Won't Connect to SQL Server .NET Core 3.0 Docker Container Won't Connect to SQL Server docker docker

.NET Core 3.0 Docker Container Won't Connect to SQL Server


This appears to be due to the TLS version used by the Linux image. With help from .NET Core team at GitHub we changed the image from buster-slim to bionic in the Dockerfile.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-bionic AS baseWORKDIR /appEXPOSE 80FROM mcr.microsoft.com/dotnet/core/sdk:3.0-bionic AS build

https://github.com/dotnet/SqlClient/issues/222


Changing to -bionic might not be enough for some developer which using SQL Server locally.

For someone using SQL Server locally (localhost), changing the connection string, Data Source from localhost to specified IP might resolve the problem.

"ConnectionStrings": {"myDb1": "Data Source=DESKTOP-MGSE697;Initial Catalog=master;User ID=sa;Password=xxx"}"ConnectionStrings": {"myDb1": "Data Source=xxx.xxx.xxx.xxx,1433;Initial Catalog=master;User ID=sa;Password=123456"}

In most case, the TCP\IP protocol of SQL Server Configuration manager is not enabled yet. Changing them in "Computer Management" => SQL Server Config Manager => Protocols for MSSQLSERVER (in my case).

Screenshot of Computer Management