1

Using Entity Framework 6 in an ASP.NET Core Web API.

I have the following controller:

[Route("[controller]/[action]")]
[ApiController]
public class ContactController : ControllerBase
{
    FalconDataContext _context;

    public ContactController(FalconDataContext context)
    {
        _context = context;
    }

    [HttpGet]
    public async Task<ActionResult<IEnumerable<ContactModel>>> GetAllContacts()
    {
        var contacts = await _context.Contacts.ToListAsync();
        return Ok(contacts);
    }
}

When I run this in Swagger I get

An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure' to the 'UseSqlServer' call

on the call to DbContext.

This just started happening. It was working a few day ago. What is this and how do I solve it?

2
  • did you configure you dbcontext properly in program.cs Commented Apr 18 at 12:53
  • 1
    user Scope base di for db context in program cs Commented Apr 18 at 12:53

1 Answer 1

0

When the Controller try to connect to database, some error ocurred. Probrably retry is already enabled and the connection is succesful in second attempt, then it shows there was a transient failure.

Maybe there is a problem with your connection to your db instance. You need to track and diagnose where is the failure (network, authentication, and so on).

Some examples: First connection try a TLS version not allowed, next connection is ok.

Azure instance shutdowns after some idle time to reduce costs and restarts when needed, then second connection is ok.

You need to diagnose your setup to solve.

Sign up to request clarification or add additional context in comments.

3 Comments

OK so I just created a simple test API trying to connect to the same data, and it fails with the same message
You need to track and diagnose the connection between application pool and your database. Another API probrably will have the same problem as it will be hosted in the same environment. Check the application logs and the database.logs.
If these logs won't help then check event viewer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.