Last post Apr 19, 2021 06:56 AM by YihuiSun
Apr 17, 2021 02:08 PM|isc98|LINK
I wanna build a web app that contains a page where I can allocate courses to professors-I already created the login-logout/register pages using Identity API-, in order to do this, I am using Razor Pages Entity Framework (CRUD). I already had some migrations
before and I want to add another migration called 'InitialCreate'. I typed the following commands in Packet Manager Console:
Add-Migration InitialCreate -Context ApplicationDbContext
Update-Database -Context ApplicationDbContext
Everything built successfully, but when I run the code and trying to access the page 'AlocareMaterii" whicht uses the migration through my localhost (localhost:x/AlocareMaterii), I get the following error:
A database operation failed while processing the request.
SqlException: Cannot open database "razor_licenta_runtimeContext-a7b890ea-d1ed-4faa-afdf-88dcf8d382d4" requested by the login. The login failed. Login failed for user 'DESKTOP-3AH99PG\ninex'.
Use migrations to create the database for razor_licenta_runtimeContext
In Visual Studio, use the Package Manager Console to scaffold a new migration and apply it to the database:
PM> Add-Migration [migration name]
Alternatively, you can scaffold a new migration and apply it from a command prompt at your project directory:
> dotnet ef migrations add [migration name]
> dotnet ef database update
This is my 'appsettings.json' file:
Apr 19, 2021 06:56 AM|YihuiSun|LINK
You need to go into SQL Server Object Explorer or SQL Server Management Studio and add 'DESKTOP-3AH99PG\ninex' as a login to SQL Server and a user in your database.
click this link to view the marked answer, which tells you in detail how to solve this problem.