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.
- Is this true? In that case, where or how can I find both names?
- 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
I’ve spent some time solving this message
SQL Server Pre-Login Handshake
Solution 1 (Encryption in client container):
Dockerfile client (github issue)
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):
Note: There are some comments about this github issue
Adding the following to the client’s connection string solved it for me:
;TrustServerCertificate=true