skip to Main Content

Our project, which is built on .NET 8, is encountering an issue when trying to connect to our SQL server (version 11.0.5058). The Docker file for our project is as follows:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime

WORKDIR /app
EXPOSE 80

ENV ASPNETCORE_URLS=http://+:80
Copy . .

RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl.cnf

RUN cat /etc/ssl/openssl.cnf

ENTRYPOINT ["dotnet", "Api.dll"]

when I want to open a SQL connection I get this error :

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

Connection String:

server=(myserver);Database=MyDB;uid=MYUSER;pwd=PASS;TrustServerCertificate=true

We’ve tried all the solutions mentioned in this GitHub issue, but unfortunately, none of them have resolved our problem.

We’re hoping you might be able to assist us in resolving this issue. Thank you in advance for your help!

2

Answers


  1. Chosen as BEST ANSWER

    Finally I found the solution , the latest comment on #2242 works for me.

    RUN sed -i 's/[openssl_init]/# [openssl_init]/' /etc/ssl/openssl.cnf
    
    
    RUN printf "nn[openssl_init]nssl_conf = ssl_sect" >> /etc/ssl/openssl.cnf
    RUN printf "nn[ssl_sect]nsystem_default = ssl_default_sect" >> /etc/ssl/openssl.cnf
    RUN printf "nn[ssl_default_sect]nMinProtocol = TLSv1nCipherString = DEFAULT@SECLEVEL=0n" >> /etc/ssl/openssl.cnf
    

  2. Try using TrustServerCertificate=true in the connection string. You can also refer this – CRUD Operations in ASP.NET Core and SQL Server with Docker which does the same thing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search