Home > database >  Can't add migration for SQL Server database only in ASP.NET Core
Can't add migration for SQL Server database only in ASP.NET Core

Time:01-14

Unable to connect to local SQL Server in my asp.net core application. When I try to add a new migration or update the database I get an error. This is not a problem in SQL Server (I think) because I can connect in SSMS and in a non-web application.

Connection string:

"Server=COMPSEMION; Initial Catalog=eBookShop; Trusted_Connection=True;"

SQL Server uses Windows authentication. But I am getting an error:

Microsoft.Data.SqlClient.SqlException (0x80131904): `Cannot open database "eBookShop" requested by the login. The login failed. Login failed for user <username>.`

Also I get the following:

Error Number:4060,State:1,Class:11

I can provide more information if needed and would appreciate any help. I'm really confused because my other WPF project connects to the same database without problems.

P.S The connection string does not seem to change at runtime

CodePudding user response:

I had this error in my project before,check the link below,you will find your answer:

Scaffold-DbContext "Login Failed" "Error Number:4060,State:1,Class:11"

CodePudding user response:

I figured out what the problem was and could fix it. Thanks @PanagiotisKanavos pointed me to the answer.

I went into Sql Server Configuration Manager and enabled the TCP/IP protocol

Then I changed the connection string:

Data Source=COMPSEMION; Initial Catalog=eBookShop; Integrated Security=True

And it works.

  •  Tags:  
  • Related