0

I am learning ASP.NET core 6 Multitier architecture. I tried making connection to database but I keep getting this error:

Error Number:4060,State:1,Class:11
Cannot open database "Blogging" requested by the login. 
The login failed.
Login failed for user 'TECHRITOMA\TECHRITOMA Inc'.

I tried using the command :

 Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

and i was expecting the model class to be created.

Sydney_dev
  • 1,448
  • 2
  • 17
  • 24
  • Can you right click the database in Solution Explorer in Visual Studio, then select properties. and verify the connectionstring – Vivek Nuna Nov 18 '22 at 03:38
  • Please check this: https://stackoverflow.com/questions/48736620/scaffold-dbcontext-login-failed-error-number4060-state1-class11 – Sydney_dev Nov 18 '22 at 04:22
  • Does this answer your question? [Scaffold-DbContext "Login Failed" "Error Number:4060,State:1,Class:11"](https://stackoverflow.com/questions/48736620/scaffold-dbcontext-login-failed-error-number4060-state1-class11) – Sydney_dev Nov 18 '22 at 04:25

1 Answers1

0

As Sydney_dev said. First, Visual studio needs to successfully connect to the local database. Official document: SQL Server Express LocalDB.

.NET Core+EF Scaffold-DbContext command uses.

Scaffold-DbContext "Data Source=ip address;Initial Catalog=database name;User ID=account;password=password;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models;

Scaffold-DbContext "Data Source=ip address;Initial Catalog=database name;User ID=account;password=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables "Blog","Post" -ContextDir Context -Context BlogContext - ContextNamespace New.Namespace

Official document.

sssr
  • 364
  • 1
  • 6