I am trying to connect to my SQL Server local database:
builder.Services.AddDbContextPool<UserDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("ConnectionString"), o =>
{
o.EnableRetryOnFailure();
});
});
API controller:
[ApiController]
[Route("[controller]")]
public class UserController : Controller
{
private readonly UserDbContext userDbContext;
public UserController(UserDbContext dbContext) => userDbContext = dbContext;
[HttpGet]
[Route("all")]
public ActionResult<IEnumerable<User>> GetAllUsers()
{
IEnumerable<User> allUsers = userDbContext.Users;
return Ok(allUsers);
}
}
And here is my connection string:
"ConnectionString": "server=(localdb)\\MSSQLLocalDB;Database=todoapp;User ID=todouser;Password=1234"
Now, when I am trying to send GET request, I get response:
Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user 'todouser'.
With SQL Server Management Studio, I can connect to the database without any problems. Server authentication is set to: "SQL Server and Windows authentication mode", but I cannot connect with Windows authentication as well.