I am doing local development of a .NET 9 Web API. It’s using a local instance of SqlServer Express with Entity Framework Core. However, after setting up my DBContext and generating my Migrations for the first time, when I went to run the dotnet ef database update
command, I received the follow error message:
Microsoft.Data.SqlClient.SqlException (0x80131904): 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.)
While this looks intimidating, it’s actually pretty easy to fix. The problem was with my ConnectionString. The ConnectionString looked like this:
"ConnectionStrings": {
"default": "Server=MYPC\\SQLEXPRESS;Database=DemoDB;User Id=SA;Password=SuperSecretPassword;"
}
Unfortunately for local development, I was missing 2 things Trusted_Connection=True;TrustServerCertificate=True;
. Once I made my ConnectionString look like this:
"ConnectionStrings": {
"default": "Server=MYPC\\SQLEXPRESS;Database=DemoDB;User Id=SA;Password=SuperSecretPassword;Trusted_Connection=True;TrustServerCertificate=True;"
}
All I had to do was rerun my dotnet ef database update
command and everything functioned as planned.