Entity Framework timeout instantly
I have a开发者_JS百科 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.ObjectQuery
1.GetResults(Nullable
1 forMergeOption) at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source) at System.Data.Objects.ELinq.ObjectQueryProvider.b__2[TResult](IEnumerable1 sequence) at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
1 query, Expression queryRoot) 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.
精彩评论