Connection closed when doing Transaction rollback on Mysql with Entity Framework 6 and Devart provider

c# devart entity-framework-6 mysql transactions


I'm working on a project that uses Entity Framework 6 RC to connect to a Mysql database with the Devart provider(v7.8.322.0).

But now I run into a problem that when a query fails, the rollback of the transaction fails because the connection is closed.

We are not starting any transactions ourselves.

This is the stacktrace of the exception:

    System.InvalidOperationException: Connection must be opened.
      at Devart.Common.Utils.CheckConnectionOpen(IDbConnection connection)
   at Devart.Data.MySql.MySqlConnection.Rollback()
   at Devart.Data.MySql.MySqlTransaction.Dispose(Boolean disposing)
   at System.Data.Common.DbTransaction.Dispose()
   at System.Data.Entity.Core.EntityClient.EntityTransaction.Dispose(Boolean disposing)
   at System.Data.Common.DbTransaction.Dispose()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass28.<SaveChanges>b__25()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at Nallian.Dal.MySql.NallianDbContext.Nallian.Data.Common.Contracts.IUnitOfWork.SaveChanges() in c:\TFS2012\Nallian\Main\Nallian.Dal.MySql\NallianDbContext.cs:line 117

Even stranger is that when I use the devart dbmonitor tool, I see the transaction getting commited.

I had a look in the Entity Framework open source code and in ObjectContext.ExecuteInTransaction I see a call to ReleaseConnection() in the general catch. In that method the connection gets closed if it is determined that nobody is using it any more. But in the finally block the transaction gets disposed (aka rollback).

So I am a bit lost here. Can anybody help me with this?

Thx, Steven.

UPDATE I build a small test project with the RTM of EF6 and the latest version of the Devart provider 8.0.17 but with the same result as above.

I also pointed my test project to SqlServer Express and there it works perfectly. So I think I have to start looking at the Devart provider.

10/21/2013 10:54:35 AM

Accepted Answer

I downloaded the new version 8.1.45 of Devart DotConnect and this has solved the problem completely. Now my transactions get a rollback if any query in them gets an error. And I get the correct exception in my EF6 Executionstrategy.

So problem solved. Thx Devart. :)

11/30/2013 7:44:29 PM

Popular Answer

The bug, related to the "Connection must be opened" error when rolling back a transaction if a connection has been already closed, is fixed.

New version of dotConnect for MySQL 8.1 is released. It can be downloaded from here (trial version) or from Registered Users' Area (for users with active subscription only). For more information, please refer to our forum .

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow