1

I've got some code which is throwing an exception when I use this against SqlServer CE 4.0 & within a TransactionScope. First, the code, then the error.

// Arrange.
// ... some stuff ...
// like .. order = get order with ID #1.

// Act.
using (new TransactionScope())
{
    order.Name = name; // Update a field.
    _orderRepository.Save(order);
    _unitOfWork.Commit(); // <-- this works 100% fine.

    // Assert.
    // Reload the order so we can see if the data persisted to the DB.
    var updatedOrder = _orderRepository
    .Find()
    .Where(x => x.OrderId == 1)
    .SingleOrDefault(); <-- // this throws the exception.

    Assert.IsNotNull(updatedOrder);
    Assert.AreEqual(name, order.Name);
}

The exception error is:-

System.Data.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: The connection object can not be enlisted in transaction scope.

So the first save/commit works fine but when I try to retrieve the object again (to see if the data persisted in the transaction) that's when the error occurs.

Now i'm sure this is a Single Transaction and not a Distributed Transaction ... so I'm assuming this should just work?

Suggestions, kind folk?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • SQLCE does not support TransactionScope. Use normal DB transactions. – leppie Jan 23 '11 at 05:40
  • BTW this was asked a few weeks ago, but I cannot find the question now. – leppie Jan 23 '11 at 05:43
  • Possible duplicate: http://stackoverflow.com/questions/1554473/linq-to-sql-does-sql-server-compact-ce-support-a-requiresnew-transaction-scop – leppie Jan 23 '11 at 05:44

1 Answers1

0

I had to fight with it and here is the possible solution: http://fknet.wordpress.com/2011/02/25/entity-framework-problemsolution-of-default-connection-closing/

frantisek
  • 366
  • 1
  • 4
  • 8