EF: The underlying provider failed on Open

asp.net azure c# entity-framework


In production I have started getting this error all across my app:

The underlying provider failed on Open

As far as I could tell, I'm not getting this error when testing the app locally (at least I could not get it no matter what I did). I'm using Azure SQL server and here is my connection string:

    <add name="DefaultConnection" connectionString="Data Source=myserver.windows.net,1433;Database=mydb;User ID=username;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />

Here is one of methods where I'm getting error:

public IEnumerable<Country> GetCountries()
        List<Country> countries;
        using (var databaseContext = new Database())
            countries = databaseContext.Countries.OrderBy(c => c.Name).ToList();

        return countries;

Also I want to stress out that error is not happening all the time, it happens kinda randomly. This started to happen today, I have not changed this code, nor connection sting, nor database settings, but (!) I have refactored some methods from synchronous to asynchronous - I don't know this is somehow connected to this particular problem.

Also as far as I could tell this is only happening in ASP.net Web API project, but not in ASP:net MVC project (they share same service layer and call same methods from service)

And finally here is Pastebin link to whole stack trace (I won't paste it here because it is too big): link

10/29/2015 6:09:52 PM

Popular Answer

Please see this post: Error 'The underlying provider failed on Open'.

The excerpt from the post that should resolve your issue is below:

Changing my code to the following fixed it:

using (DatabaseEntities context = new DatabaseEntities())
    // the rest
5/23/2017 12:16:44 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow