'SqlException (0x80131904): Cannot open database "DBName" requested by the login

I have the following connection string in ASP.NET Core, but I get the following error:

Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "DBName" requested by the login. The login failed. Login failed for user 'admin-PC\admin'.

In SQL log

Error: 18456, Severity: 14, State: 38. and Login failed for user 'admin-PC\admin'. Reason: Failed to open the explicitly specified database 'DBName'. [CLIENT: ]

"AllowedHosts": "*",
  "ConnectionStrings": {
    "CoreConnection": "server=.;Database=DBName;Trusted_Connection=True;MultipleActiveResultSets=true;"

How can I make it work?



Solution 1:[1]

Maybe you deleted your database? I had the same problem. So, if you have created migration, just run update-database in your Package Manager Console.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1