3

first time caller here...

I'm writing a WebAPI application that connects to an Oracle database using Oracle.ManagedDataAccess. I'm using EF6 and I'm intermittently getting

"Unexpected connection state. When using a wrapping provider ensure that the StateChange event is implemented on the wrapped DbConnection."

I'm using Autofac and have everything registered as "InstancePerDependency" (also tried InstancePerRequest) so I should be getting a new instance each request but it seems as soon as my connection gets into this state it can't recover.

I've tried turning connection pooling off and also calling Dispose() on my connection.

Does anyone know what the reason is behind this behavior or give some additional details on what this exception means as Oracle.ManagedDataAccess.Client.OracleConnection appears to implement the StateChange event.

Thanks!

Here's the stack trace:

at System.Data.Entity.Core.Objects.ObjectContext.EnsureContextIsEnlistedInCurrentTransaction[T](Transaction currentTransaction, Func1 openConnection, T defaultValue) at System.Data.Entity.Core.Objects.ObjectContext.<EnsureConnectionAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__3d1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult() at System.Data.Entity.Core.Objects.ObjectQuery1.d__e.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult() at System.Data.Entity.Internal.LazyAsyncEnumerator1.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.d__25`1.MoveNext()

NeilCampbell
  • 43
  • 1
  • 6
  • I had referenced a Nuget package which 'helpfully' cleared the DbProviderFactories and replaced them with different versions. No one will ever have this problem so if you're looking here for the answer to your problem then this is certainly not it! – NeilCampbell Oct 02 '17 at 14:25

0 Answers0