SijoX
SijoX

Reputation: 107

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

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

Upvotes: 4

Views: 1312

Answers (2)

SijoX
SijoX

Reputation: 107

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

Upvotes: 1

Rakesh Gupta
Rakesh Gupta

Reputation: 3770

Please add ;TrustServerCertificate=true to your connection string.

Upvotes: 2

Related Questions