I am trying to connect my .NET Core application to SQL Server using a connection string. However it is failing and I get this error:
login failed for user
This is the connection string I am using
"ConnectionStrings": {
"DefaultSQLConnection": "Server=DESKTOP-User\\MSSQLSERVER;Database=VillaDatabase;TrustServerCertificate=True;"
}
Below is the line of code I am using in my Program.cs file:
builder.Services.AddDbContext<ApplicationDbContext>(option =>
{
option.UseSqlServer(builder.Configuration.GetConnectionString("DefaultSQLConnection"));
});
I am currently using .NET Core 7.
Can anyone please tell me what could be the fix for this?

IIS_IUSRSwhich most likely hasn't been granted access to your DB. Either run the website in an explicit account or specify SQL Username+password in your config.