MSSQL Error 'The underlying provider failed on Open' using WCF & EntityFramework
<p>I use the <strong>EntityFramework 6</strong> to make database queries:</p>
<pre><code>public class Entities : DbContext {
    public Entities ();

    public DbSet&lt;Analysis&gt; Analysis { get; set; }
}

public class TableController {
    public function List&lt;DataSet&gt; GetDataSets () {

        var query = &quot;SELECT ... FROM ... WHERE ...&quot;;

        var queryReturnType = typeof(Analysis);

        var result = this.Entities.Database.SqlQuery(queryReturnType, query);
        
        foreach (var elem in result) {
             ...
        }        
    }
}
</code></pre>
<p>I use all of this in a self-hosting WCF-service, which allows multi-threading:</p>
<pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class RestService : IRestService {
    ...
}
</code></pre>
<p><strong>The query works fine for 90%-95% of all requests</strong>, but sometimes I receive an exception from the <strong>EntityFramework</strong> at the line where I try to iterate over the results of the query (<code>foreach</code>):</p>
<blockquote>
<p>Error with underlying provider with open</p>
<p>at System.Data.Entity.Core.EntityClient.EntityConnection.Open()</p>
<p>at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)</p>
<p>at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func'1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)</p>
<p>at System.Data.Entity.Core.Objects.ObjectContext.&lt;&gt;c__DisplayClass65'1.b__63()</p>
<p>at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func'1 operation)</p>
<p>at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)</p>
<p>at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, ExecutionOptions executionOptions, Object[] parameters)</p>
<p>at System.Data.Entity.Internal.InternalContext.&lt;&gt;c__DisplayClass14'1.b__13()</p>
<p>at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()</p>
</blockquote>
<p>The service is hosted on a <strong>Windows Server 2012 R2</strong> and when I execute the service on a local <strong>Windows 10</strong> machine, there error does not occure.</p>
<p>What may cause the error?</p>