title: EntityException: The underlying provider failed on Open
body: <p>I'm having a problem connecting to my database using Entity Framework. I'm randomly getting the following error when attempting to connect to the database...</p>
  
  <pre><code>EntityException: The underlying provider failed on Open.
  The connection was not closed. The connection's current state is connecting.
  </code></pre>
  
  <p>To give you some background on my setup, I'm using MVC 4 and Ninject. I'm also using the Repository and Unit of Work pattern described in <a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application" rel="nofollow">this article</a>. I'm using the default NinjectWebCommon file in MVC 4 and my RegisterServices method is as follows...</p>
  
  <pre><code>private static void RegisterServices(IKernel kernel)
  {
      kernel.Bind&lt;IMyEntities&gt;().To&lt;MyEntities&gt;();
      kernel.Bind&lt;IUnitOfWork&gt;().To&lt;UnitOfWork&gt;().InRequestScope();
      // UnitOfWork has a dependency on MyEntities
  
      kernel.Bind&lt;IAccountManager&gt;().To&lt;AccountManager&gt;(); 
      kernel.Bind&lt;ITransactionManager&gt;().To&lt;TransactionManager&gt;(); 
      // AccountManager and TransactionManager has a dependency on UnitOfWork
  }
  </code></pre>
  
  <p>My page loads fine but I have 2 ajax calls on the page that cause the error. When the ajax calls are removed, the error never occurs. When there's only 1 of the ajax calls made, the error never occurs. It's only when both calls are made simultaneously that the error occurs.</p>
  
  <p>Here are the 2 different web api controllers...</p>
  
  <pre><code>public class AccountController : ApiController
  {
      private readonly IAccountManager _AccountManager;
  
      public AccountController(IAccountManager accountManager)
      {
          _AccountManager = accountManager;
      }
  
      public HttpResponseMessage Get()
      {
          IEnumerable&lt;Account&gt; accounts = _AccountManager.Get();
          return Request.CreateResponse(HttpStatusCode.OK, accounts);
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class TransactionController : ApiController
  {
      private readonly ITransactionManager _TransactionManager;
  
      public TransactionController(ITransactionManager transactionManager)
      {
          _TransactionManager = transactionManager;
      }
  
      public HttpResponseMessage Get()
      {
          IEnumerable&lt;Transaction&gt; transactions = _TransactionManager.Get();
          return Request.CreateResponse(HttpStatusCode.OK, transactions);
      }
  }
  </code></pre>
  
  <p>I really don't know what to do here. I've read every article relating to this on StackOverflow and Google but I can't find an answer. Does anyone have any idea what I can do to stop this issue from happening?</p>