实体框架立即超时
我对 400 条记录的数据库有一个非常简单的查询,但是,如果我在多线程环境中执行该查询,它会立即超时,如果我一条一条地查询它,它工作正常。
我没有对连接字符串做任何特殊的事情,SQL Server 在本地运行。
每个线程创建自己的上下文并在 using
块中执行查询。
第一次超时大约需要 15 秒,然后后续查询立即超时。
我尝试更改 CommandTimeout 的超时,但没有成功,并且即时超时看起来很可疑,我认为最好进一步深入研究。
查询只是通过entity.Id 进行匹配。看来这与查询本身无关,因为我多次更改查询来执行不同的操作。
异常说
10/10/2011 3:52:16 pm T026 D 异常 - 底层提供程序在打开时失败。
10/10/2011 3:52:16 pm T026 D 内部异常消息 - 超时已过期。操作完成之前超时时间已过,或者服务器没有响应。
10/10/2011 3:52:16 pm T026 D at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptsOperation, Boolean& closeStoreConnectionOnFailure) 在 System.Data.EntityClient.EntityConnection.Open() 在 System.Data.Objects.ObjectContext.EnsureConnection() 在 System.Data.Objects.ObjectQuery
1.GetResults(Nullable
1 forMergeOption) 在 System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable
1 源) 在 System.Data.Objects.ELinq.ObjectQueryProvider.b__2[TResult](IEnumerable.GetEnumerator() 在 System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable 1 序列) 在 System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
1 查询,表达式 queryRoot) 在 System.Data.Objects.CompiledQuery.ExecuteQuery[TResult](ObjectContext 上下文,Object[] 参数值) 在 System.Data.Objects.CompiledQuery.Invoke[TArg0,TArg1,TResult](TArg0 arg0, TArg1 arg1)
有没有人经历过同样的事情或知道为什么会立即超时?
提前致谢。
I have a very simple query on a 400 records database, however, if I do that query in a multi-threaded environment, it times out instantly, if I query it one by one, it works fine.
I did not do anything special to connection string, SQL server is running locally.
Each thread creates its own context and do the query within a using
block.
The first timeout takes about 15 seconds and then following queries timeout instantly.
I tried to change timeout on CommandTimeout but did not work, and instant timeout looks suspicious, I think mgiht be good to dig it down further.
The query is simply match by entity.Id. It seems it is nothing to do with the query itself as I changed the query multiple times to do different things.
The exception says
10/10/2011 3:52:16 p.m. T026 D Exception - The underlying provider failed on Open.
10/10/2011 3:52:16 p.m. T026 D Inner Exception Message - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
10/10/2011 3:52:16 p.m. T026 D at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery1.GetResults(Nullable
1 forMergeOption)
at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
1 source)
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
at System.Data.Objects.ELinq.ObjectQueryProvider.b__2[TResult](IEnumerable1 sequence)
1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
at System.Data.Objects.CompiledQuery.ExecuteQuery[TResult](ObjectContext context, Object[] parameterValues)
at System.Data.Objects.CompiledQuery.Invoke[TArg0,TArg1,TResult](TArg0 arg0, TArg1 arg1)
Has any body experienced the same or know the answer why is the instant timeout?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论