Recently I was working on migration of an existing Asp.Net MVC project to .Net 6 (.Net Core). I started getting following error when establishing SQL connection with Microsoft SQL Server.
Exception thrown: 'Microsoft.Data.SqlClient.SqlException' in Microsoft.Data.SqlClient.dll An exception of type 'Microsoft.Data.SqlClient.SqlException' occurred in Microsoft.Data.SqlClient.dll but was not handled in user code 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
This is one of the breaking changes in SQL Server driver. Now the driver wants to enforce a valid security certificate for each connection. This does not mean that you do not have an option to not use this security behavior. You can set TrustServerCertificate=True. This will ensure that every SQLConnection that uses this connection string will not encounter the error mentioned above. Following is an example of a connection string I use in my application."Server=localhost;TrustServerCertificate=True;Database=mydatastore;uid=myuser;pwd=mypassword"