47

I recently upgraded to Entity Framework Core 7 in development and I'm getting an exception:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

I am using Microsoft SQL Server Developer (64-bit). I have tried to make changes in the VS2022 Server Explorer to disable encryption and to trust the server certificate, I don't have one installed, but the exception remains. How can this be mitigated in development?

6 Answers 6

95

It is not a bug in EF Core 7.0, instead it is improved security. Microsoft suggests either of the following 3 solutions, whichever applies to you:

  1. Install a valid certificate.
  2. Add TrustServerCertificate=True to the connectionstring
  3. Add Encrypt=False to the connectionstring

Old behavior
SqlClient connection strings use Encrypt=False by default. This allows connections on development machines where the local server does not have a valid certificate.

New behavior
SqlClient connection strings use Encrypt=True by default. This means that:

  • The server must be configured with a valid certificate
  • The client must trust this certificate

If these conditions are not met, then a SqlException will be thrown. For example:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes

1
31

Same problem here after upgrading Microsoft.EntityFrameworkCore.SqlServer to 7.0.0

I fixed that by adding TrustServerCertificate=Yes to the SQL Server connection string.

1
  • 1
    So glad I ran across this. Thank you for posting. Solved my connecting issue. Commented Jan 19, 2023 at 5:37
0

The Below code worked for .net core 6 & 7

> "ConnectionStrings": {
>     "SqlServer": "Data Source=DESKTOP-*****;Initial Catalog=Test;Integrated Security=True;TrustServerCertificate=Yes",
> "LocalSqlProviderEnable": true   }
1
  • 2
    This adds nothing to the highest voted answer which is the only answer that has decent and comprehensive explanation. Commented Jan 11 at 11:54
-2

I think it's fails because is a recent update. I had the same problem and I fixed it re installing the previous version (6.0.11). I hope this comment helps you.

2
  • I did the same thing, so I could keep working. I guess I'll have to wait for an EF Core 7 update.. Commented Nov 18, 2022 at 15:41
  • 2
    This is not an error, and the update will not fix this, you should update to the version 7, and disable the encryption please take a look on my answer bellow.
    – hassane
    Commented Nov 25, 2022 at 19:59
-2

It seems the answer is to await an update to EF Core 7. This should be a bug. My development is all on one machine with a SQL Server Development Edition instance. I suppose using localdb might be an approach.

2
  • I have two solutions running against the same SQL Server database. One is an ASP.NET Core 7 solution that uses EF Core 7 without an problem. Is uses a connection string in User Secrets. The other is a .NET Core 7 Console application that uses EF Core Power Tools to reverse engineer the database. This version has the certificate chain error in connecting to the database. I rolled it back to EF Core 6.0.11 to get it to work. I don't know what the issue is between the two solutions, but I include it here for the record. Perhaps someone can enlighten me on what is going on. Commented Nov 20, 2022 at 16:24
  • It's not a bug. It's not even an EF issue. Commented Jan 11 at 11:52
-3

After adding Encrypt=False in the connection string it resolved the issue.

"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CommunicationDB;Trusted_Connection=True;MultipleActiveResultSets=True;Encrypt=False;"
1
  • 1
    Please don't affirm answers by repeating them. This was already said in this answer. Vote for helpful answers instead. Commented Jan 5, 2023 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.