Entity Framework Core Error: provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted


I recently started working on a new project based on .NET Core Framework 7. In this project, I'm using Entity Framework Core 7. However, when I try to build and run my project, I encounter 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.)' After searching online, I found a solution, so I thought I'd share it.

So let me share my thoughts on that. It's not a bug in EF Core 7.0 or 8.0; instead, it's an improved security feature. If you visit the Microsoft website, it suggests three options you can use: 
1. Install a valid certificate. 
2. Add 'TrustServerCertificate=True' to the connection string. 
3. Add 'Encrypt=False' to the connection string. 

Previously, SqlClient connection strings used 'Encrypt=False' by default. This allowed connections on development machines where the local server did not have a valid certificate. 

However, in the latest version, SqlClient connection strings use 'Encrypt=True' by default. 

This means the server must be configured with a valid certificate. That's why we now need to set the 'Encrypt' property to 'false' in case we don't have a valid certificate. 
The connection string will look like the following:
Data Source=DESKTOP-MFLCOI2;Initial Catalog=HollyMelodyDb;User ID=sa;Password=adk@1234;Encrypt=false;