skip to Main Content

I’m working on a Docker related application, written in C#, based on Entity Framework.

One of the Docker containers, is the ms-sql-server, which is used for database access.
In order to access the SQL-server, following connectionString is created:

Server=ms-sql-server;Initial Catalog=Ownobjects;User ID=SA;Password=some_password

While performing following source code:

public void InitialiseDatabase(IApplicationBuilder app)
{
  using (var context = app.ApplicationServices.GetRequiredService<ApplicationDbContext>())
  {
    context.Database.EnsureCreated();
    ...

… I get following Exception:

Microsoft.Data.SqlClient.SqlException: '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)'  

Inner Exception  
AuthenticationException: The remote certificate was rejected
  by the provided RemoteCertificateValidationCallback.

According to this similar StackOverflow post, two things might not match: the instance name in the connection string and the expected name from the instance.

  1. Is this true? In that case, where or how can I find both names?
  2. If this is not true, then what might be causing this issue?

Edit:
Some further examination:
In the Logs of the ms-sql-server Docker container, I’ve found following line:

Server name is 'e614890825ac'.
This is an informational message only.
No user action is required

I’ve used this entry in the connectionString but then the same Exception is raised, but this time with following Inner Exception::

ExtendedSocketException: Resource temporarily unavailable

Edit2:
Again some further examination:
In the meantime I’ve discovered that my original servername in the connectionString is correct.

Thanks in advance

2

Answers


  1. I’ve spent some time solving this message SQL Server Pre-Login Handshake

    Solution 1 (Encryption in client container):

    Dockerfile client (github issue)

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
    # ...
    
    # SQL Server trusted connection problem
    RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2/CipherString = DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
    
    # ...
    

    Note: There’s no need to change your connection string adding Encrypt=false or anything else with this setting

    Note 2: I’have tried to use focal and other linux images and only aspnet:6.0 works with this setting.

    Solution 2 (Image version or storage problems):

    • Change the runtime version of the client container (see github comments)
    • Replace the binding storage or volume in sql server container. This could be a user access problem.

    Note: There are some comments about this github issue

    Login or Signup to reply.
  2. Adding the following to the client’s connection string solved it for me:

    ;TrustServerCertificate=true

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