Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 741
SijoX Avatar asked Oct 16 '25 05:10

SijoX


1 Answers

Please add ;TrustServerCertificate=true to your connection string.

like image 156
Rakesh Gupta Avatar answered Oct 18 '25 01:10

Rakesh Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!