实体框架例外"底层提供程序未能在开放与QUOT; [英] Entity Framework Exception "The underlying provider failed on Open"

查看:313
本文介绍了实体框架例外"底层提供程序未能在开放与QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个窗口服务,听一个TCP / IP端口和保存使用实体框架数据库接收到的数据。大多数时候,它工作正常,但过一段时间它抛出一个异常基础提供失败的开放。在数据库中保存数据。
这里是我的异常详细信息:

I have created a windows service which listen to a TCP/IP port and save received data in database using Entity Framework. Most of the time it works fine but some time its throwing an exception "The underlying provider failed on open." on save data in database. Here is my exception details:

    Exception: 2/27/2014 10:31 AM:
    The underlying provider failed on Open.
     at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
     at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection()
     at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
     at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
     at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
     at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
    at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
     at System.Lazy`1.CreateValue()
     at System.Lazy`1.LazyInitValue()
     at System.Lazy`1.get_Value()
     at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
     at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
     at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
     at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
    at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
    at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
    at Service.DemoService.Save(String received, TcpClient client)

这是什么例外背后的事情,如何解决呢?

What is the thing behind this exception and how to resolve it?

推荐答案

一般情况下,实体框架时,你就需要启用的多活动结果集的连接字符串中设置的 MultipleActiveResultSets 的选项的真正的如下:

Usually, when working with Entity Framework you'll need to enable the multiple active result sets option in your connection string by setting MultipleActiveResultSets to true as follows.

<add name="conn" 
  connectionString="
    Data Source=.\;
    Initial Catalog=TDB;
    UID=admin123;
    PWD=123;
    MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />

验证它是否解决您的问题。

Verify that it solves your problem.

这篇关于实体框架例外&QUOT;底层提供程序未能在开放与QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆