I received the same error message while connecting to a local database through MSBuild recently. It ended up being a certificate issue. I was able to fix it by adding TrustServerCertificate=True
to the MSBuild connection string. Note that this is risky in a production context.