Monday, June 4, 2012

WCF Data Service (OData) Devart Error: The underlying provider failed on Open.( The connection was not closed.)

Solution 
This problem  can be fixed applying synchronization around Data Service ObjectContext  instance



lock (MyObjectContext)
     {
          //Do your queries here
     }


Root Cause
This problem with Devart Data Driver  that is not able to handle object connection request properly in multithreaded environment  and tried to open an already open connection.
Error Stack Trace  

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
  <innererror>
    <message>The underlying provider failed on Open.</message>
    <type>System.Data.EntityException</type>
    <stacktrace>
      at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean&amp; closeStoreConnectionOnFailure)&#xD;
      at System.Data.EntityClient.EntityConnection.Open()&#xD;
      at System.Data.Objects.ObjectContext.EnsureConnection()&#xD;
      at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)&#xD;
      at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()&#xD;
      .... some private code
     at System.Data.Objects.ObjectContext.OnObjectMaterialized(Object entity)&#xD;
      at System.Data.Common.Internal.Materialization.Shaper.RaiseMaterializedEvents()&#xD;
      at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()&#xD;
      at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)&#xD;
      at System.Data.Services.DataService`1.HandleRequest()
    </stacktrace>
    <internalexception>
      <message>The connection was not closed.</message>
      <type>System.InvalidOperationException</type>
      <stacktrace>
        at Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)&#xD;
        at Devart.Common.DbConnectionBase.Open()&#xD;
        at Devart.Data.Oracle.OracleConnection.Open()&#xD;
        at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean&amp; closeStoreConnectionOnFailure)
      </stacktrace>
    </internalexception>
  </innererror>
</error>


References 
http://forums.devart.com/viewtopic.php?t=22987


No comments:

Post a Comment