Note that there are some explanatory texts on larger screens.

plurals
  1. PO"The underlying provider failed on Open" Error when using EF5 Code First with Unity IoC in Azure Worker Role against SQL Azure
    primarykey
    data
    text
    <p>I am using Entity Framework 5 Code First, I use the repository and unit of work pattern, and have my domain models, repositories, and service layer working fine within an MVC app running in a Windows Azure cloud service. I'm using Unity for IoC and inject repositories, controllers, and service classes as required, and use a per-request lifetime. It has been working great.</p> <p>However, when I use the same code/class libraries for the domain, repository, and the EF5 DbContext, in an Azure Worker Role, pointing to the same SQL Azure database as the MVC app, I get odd errors which I don't see from the MVC app. Note that at this point, I am just doing reads (select), no update transactions. The error message below seems to imply that it could not open a connection.</p> <p>In the Worker Role, I have a bootstrapper static class to build up the container and register all the services in it. In the worker role start up I have to do some work, so I call the bootstrapper to register the services, then I resolve a couple of them to use right away. Those services get injected with repositories, which in turn get injected with my DbContext, all built up by the IoC container. For the DbContext, I am using Unity's HierarchicalLifeTimeManager in the IoC container.</p> <p>When my service class tries to read data from the database while running the worker role, it gets the following error:</p> <pre><code>The underlying provider failed on Open. at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean&amp; closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at MyApp.Persistence.EF.RepositoryBase`1.Find(Expression`1 where, Expression`1[] includeProperties) </code></pre> <p>This exact same method call has been working fine from the MVC app. I am thinking there's something wrong with the scope of DbContext in the worker role, perhaps related to the lifetime in the IoC, but that's just conjecture.</p> <p>Does anyone have any idea what could be the cause of this exception? Anyone using EF, IoC, Repos/UoW, and Azure Worker roles? Suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload