Unable to connect to SQL Server from Docker container (Linux image)

Viewed 617

In our application we are using linux based container which access SQL server installed on VM. Everything works fine in local environment outside the container, But when I ran the app in local container we are getting the below error.

"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught"

appsetings.json
"ConnectionStrings": {
    
    "DbConnection": "Server=tcp:vmname\\sqlservername,49763;Database=dbname;User ID=username_Users;Password=pwd;MultipleActiveResultSets=true;Integrated Security=False;"
  }

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
.......

Any inputs will be appreciated

2 Answers

The issue was related to TLS version of the SQL server, enabling TLS 1.2 resolved the issue

Please add ;TrustServerCertificate=true to your connection string.

Related