Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker SQL-Server login problem: AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback

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

like image 426
Dominique Avatar asked Mar 22 '26 14:03

Dominique


1 Answers

Adding the following to the client's connection string solved it for me:

;TrustServerCertificate=true

like image 171
GaTechThomas Avatar answered Mar 24 '26 02:03

GaTechThomas