Cannot connect to MSSQL database from .NET 6 application

If you encounter SSL error when a .NET 6 application tries to connect to the MSSQL database

Microsoft.Data.SqlClient.SqlException : 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.)
System.ComponentModel.Win32Exception : The certificate chain was issued by an authority that is not trusted.

Not sure why, it might be that the new libraries are more strict regarding security. A workaround is to add TrustServerCertificate=True to the connection string.