简体   繁体   中英

Entity Framework Core 7 connection certificate trust exception

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?

it is not a bug in EF Core 7.0, instead it is improved security. Microsoft suggest following 3 solution, which ever 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

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.

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.

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.

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;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM