SqlException: Cannot open database "MvcMovieContext in Visual studio ASP.NET Core MVC web development with controllers and views

37 Views Asked by At

I was following tutorial of ASP.NET Core mvc in microsoft learn platform and in the add a model step after doing scaffolding movie pages in the initial migration I faced "SqlException: Cannot open database "MvcMovieContext" this issue. I followed each and every step given in the documentation. Before testing application, I entered the following commands in the Package Manager Console (PMC): "Add-Migration InitialCreate Update-Database" After running application it looks fine but when I navigate to "MovieApp" link I faced this error: An unhandled exception occurred while processing the request. SqlException: Cannot open database "MvcMovieContext-69c537e0-db41-43b6-a786-94c9779c9400" requested by the login. The login failed. Login failed for user

After Initial migration step I tried testing the app But it gave me An unhandled exception while processing the request error. SqlException: Cannot open database "MvcMovieContext-69c537e0-db41-43b6-a786-94c9779c9400" requested by the login. The login failed. Login failed for user. I checked SQL Connection string in appsettings.json and also SQL SERVER Authentication (Trusted_Connection=True) I wanted to perform crud operations and work with the database in the following steps so that i can search, add, delete details. Please consider my problem, I would appreciate your help. Thank you in advance for your consideration.

Edit: Solved the error by resetting the migrations following these steps in package manager console: Update-Database -TargetMigration:0 Add-Migration InitialCreate Update-Database

And then reapplied migration with these steps: Add-Migration InitialCreate Update-Database

After applying these steps, Tested the app with CTRL+ F5. now the app works as desired.

0

There are 0 best solutions below