9

After I migrated my project to .NET 7 I had to add the TrustServerCertificate=true; setting in the connection string otherwise the following error is thrown: SqlException: A connection was successfully established with the server, but then an error occurred during the login process.

In .NET 5 or 6 this is not necessary. Can anyone tell me why it is necessary to add this setting in the connection string?

LOCAL CONNECTION STRING:

Server=localhost;Database=Xpz;Integrated Security=SSPI;TrustServerCertificate=true;
Leomar de Souza
  • 677
  • 10
  • 23

4 Answers4

12

Write the connection string in appsettings.json file: add "TrustServerCertificate=True"

"ConnectionStrings": {
    "DefaultConnection": "Server=SERVER_NAME;Database=DB_NAME;Trusted_Connection=True;TrustServerCertificate=True;",
}
Subarata Talukder
  • 5,407
  • 2
  • 34
  • 50
8

Because of a breaking change in the SQL Server driver, see https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes#encrypt-true

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
6

I had the same problem with the .net 7.0 that just came out. TrustServerCertificate=True attribute is required for me

Sopia Xk
  • 61
  • 3
-1

Add Encrypt=False; to the connection string

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 22 '23 at 11:01