0

I started to upgrade my .NET 5/6 applications to .NET 7, I also updated from EF6 to EF7, which seems to be more difficult than expected :-(

I managed to find out that there were breaking changes in the new SqlClient (5.0.1) library, which now forces you to turn off encryption or trust the server certificate:

Encrypt = false; or TrustServerCertificate = yes

After I have set these properties in the connection string, I was again able to connect to my database.

BUT, I am using a code first approach, this means my app is creating / migrating the database if it does not exist or needs migration.

I am now running into the issue that my app is not able to create an empty database anymore. I am still getting an exception

Microsoft.Data.SqlClient.SqlException Cannot open database "XXX" requested by the login. The login failed. Login failed for user 'YYY\ZZZ'.

This only happens when I am trying to create a new database.

If I create an empty database (no scheme) manually on my SQL Server Express, all works fine, the scheme gets created and migrations applied. The issue is only the initial creation of the database itself.

Application and SQL Server Express are running on the same machine, SQL Server runs in mixed authentication mode. "Trusted Connection" is enabled in my connection string which looks like this:

Server =.\\SQLExpress; Database = TEST_DB; Trusted_Connection = Yes; Connection Timeout = 5; Encrypt = false;

Before I updated to .NET 7 everything worked fine with the exact same connection string.

Any ideas?

0 Answers0