Page 1 of 1

Occasional Timeout exception w/ Entity Framework

Posted: Tue 28 Jun 2011 14:21
by roycornelissen
Hi,

We have a couple of new web services that utilize Entity Framework with the Devart dotConnect for Oracle provider. While testing, we recently experienced a series of exceptions like this:
System.Data.EntityException: The underlying provider failed on Open. ---> Devart.Data.Oracle.OracleException: Server did not respond within the specified timeout interval


at Devart.Data.Oracle.a5.a(ae A_0, a8 A_1)
at Devart.Data.Oracle.OracleInternalConnection..ctor(ae connectionOptions, OracleInternalConnection proxyConnection)
at Devart.Data.Oracle.cr.a(j A_0, Object A_1, DbConnectionBase A_2)
at Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, j A_1, DbConnectionBase A_2)
at Devart.Common.DbConnectionPool.a(DbConnectionBase A_0)
at Devart.Common.DbConnectionPool.GetObject(DbConnectionBase owningConnection)
at Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)
at Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
at Devart.Common.DbConnectionBase.Open()
at Devart.Data.Oracle.OracleConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
--- End of inner exception stack trace ---
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.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.b__2[TResult](IEnumerable`1 sequence)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
Now the problem is that this error happens only occasionally, and usually early in the morning, when the service is called for the first time that day.

One of the things we think we did wrong was that we kept a member variable in our data access class to hold the DataContext, which was then used from our methods. We already changed this to:

Code: Select all

public void SomeMethod()
{
   using (var ctx = new DataContext())
   {
       // do operations
   }
}
But we're not confident that this is the solution to our problem. Does anyone have any other hints on what to check for to see if this solves the error or what else could cause this behavior?

Thanks!

Posted: Fri 01 Jul 2011 10:30
by AndreyR
Could you please try increasing the connection timeout in the model connection string?
This can be done by adding "ConnectionTimeout=30;" to the model connection string.
If 30 seconds is not enough, you can try to set it to 0, this value means that no timeout exception should be raised.
Please let us know about the results of changing ConnectionTimeout .

Have the same problem

Posted: Thu 16 Feb 2012 16:11
by ABCade
Hello,

I have the same problem, didn't mange to add ConnectionTimeout=30
the Key isn't known

Posted: Fri 17 Feb 2012 17:26
by Shalex
Please try using "Connection Timeout=30;" (or "Connection Timeout=0;") instead of "ConnectionTimeout=30;".

Posted: Tue 21 Feb 2012 08:18
by ABCade
OK, I can add this to the connection string, but I still have the same problem (it's just taking more time to get the error ...).

Any ideas?
What can / should I check ?

Posted: Tue 21 Feb 2012 16:22
by Shalex
ABCade, are you getting the "Server did not respond..." error occasionally or constantly?

1. Occasionally. Maybe Oracle server switches to the Sleep mode when there are no requests to it during a particular time, and it takes a lot of time to awake?

2. Constantly. Try opening a simple ADO.NET connection - OracleConnection.Open(). Does it work? If not, make sure that your Oracle server is available (check a connection with any other tool).

Posted: Tue 21 Feb 2012 20:27
by ABCade
It happens occasionally. Sometimes, one app works and another one doesn't (with the same error).
When it happens I manage to connect to the DB with sqlplus.

Posted: Tue 28 Feb 2012 13:16
by Shalex
Try switching to the OCI mode (via Oracle client) with using Transparent Application Failover.

Posted: Tue 28 Feb 2012 15:35
by ABCade
I'll try,
Can you give me some reference to using it with EntityFramework ?

BTW, changing it to working with direct=true also helps (but it's not what I want)

Posted: Wed 29 Feb 2012 15:31
by Shalex
Transparent Application Failover can be used with Entity Framework in the following way: create OracleConnection with a failover handler and pass it to the constructor of DataContext (EF v4.1/v4.2/v4.3). The scenario is more complicated when using ObjectContext (EFv1, EFv4) because EntityConnection (not OracleConnection) has to be passed to it. EntityConnection includes OracleConnection and MetadataWorkspace with loaded metadata.