Occasional Timeout exception w/ Entity Framework

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
roycornelissen
Posts: 1
Joined: Tue 28 Jun 2011 14:11

Occasional Timeout exception w/ Entity Framework

Post by roycornelissen » Tue 28 Jun 2011 14:21

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!

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 01 Jul 2011 10:30

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 .

ABCade
Posts: 8
Joined: Sun 30 Oct 2011 12:36

Have the same problem

Post by ABCade » Thu 16 Feb 2012 16:11

Hello,

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 17 Feb 2012 17:26

Please try using "Connection Timeout=30;" (or "Connection Timeout=0;") instead of "ConnectionTimeout=30;".

ABCade
Posts: 8
Joined: Sun 30 Oct 2011 12:36

Post by ABCade » Tue 21 Feb 2012 08:18

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 ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 21 Feb 2012 16:22

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).

ABCade
Posts: 8
Joined: Sun 30 Oct 2011 12:36

Post by ABCade » Tue 21 Feb 2012 20:27

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 28 Feb 2012 13:16

Try switching to the OCI mode (via Oracle client) with using Transparent Application Failover.

ABCade
Posts: 8
Joined: Sun 30 Oct 2011 12:36

Post by ABCade » Tue 28 Feb 2012 15:35

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)

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 29 Feb 2012 15:31

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.

Post Reply