简体   繁体   English

实体框架异常“底层提供程序打开失败”

[英]Entity Framework Exception “The underlying provider failed on Open”

I have created a windows service which listen to a TCP/IP port and save received data in database using Entity Framework.我创建了一个 Windows 服务,它侦听 TCP/IP 端口并使用实体框架将接收到的数据保存在数据库中。 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?此异常背后的原因是什么以及如何解决它?

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.通常,在使用实体框架时,您需要通过将MultipleActiveResultSets设置为true来启用连接字符串中的多个活动结果集选项,如下所示。

<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.验证它是否解决了您的问题。

Check whether you SQL Server is running or not.检查您的 SQL Server 是否正在运行。 Just Open Task Manager and Goto Services, Click on Services button below and check whether SQL Server is running or not.只需打开任务管理器和转到服务,单击下面的服务按钮并检查 SQL Server 是否正在运行。

In my case, the issue was that the account which I was using to connect to SQL server was not added to app pool identity.就我而言,问题是我用来连接 SQL Server 的帐户未添加到应用程序池标识中。 Once I added the account 'domain\\username' to app pool, it started working.一旦我将帐户“域\\用户名”添加到应用程序池,它就开始工作。

Change integrated security= False ;更改集成安全= False ; MultipleActiveResultSets=True in your connection string , it should be work. MultipleActiveResultSets=True 在您的连接字符串中,它应该可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架给出异常:“底层提供程序在打开时失败。” - Entity Framework giving exception : “The underlying provider failed on Open.” NServiceBus和实体框架导致异常-基础提供程序在打开时失败 - NServiceBus and Entity Framework causes exception - The underlying provider failed on Open 基础提供程序无法打开-WPF和实体框架 - The underlying provider failed to open - WPF and Entity FrameWork 实体框架底层提供程序在打开时失败 - Entity Framework The underlying provider failed on Open 基础提供程序在实体框架中打开时失败 - The underlying provider failed on Open in entity framework connection 使用WEB API和Entity Framework Project的IIS本地计算机上的“基础提供程序无法打开”异常 - “The underlying provider failed to Open” exception on IIS Local Machine using WEB API and Entity Framework Project 具有SQLite异常的实体框架:底层提供程序在Commit上失败 - Entity Framework with SQLite exception: The underlying provider failed on Commit 在实体框架上下文中使用单例模式-基础提供程序在打开时失败 - Using singleton pattern with Entity Framework context - The underlying provider failed on open 实体框架和SQL Server CE-基础提供程序在打开时失败 - Entity Framework & SQL Server CE - Underlying Provider Failed On Open SQLite&Entity Framework 6“基础数据提供程序无法打开” - SQLite & Entity Framework 6 “The underlying data provider failed to open”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM