How do you configure the Transaction time out in Entity Framework 6 DbContext.Database.BeginTransaction?

entity-framework transactions

Question

Using code like

using (var tran = Ctxt.Database.BeginTransaction()) {   

How can I set a value for the transaction timeout ?

1
7
9/25/2014 4:05:40 PM

Popular Answer

If for whatever reason you need to manage transactions yourself it is much easier to use TransactionScope. It has several constructors accepting a TimeSpan parameter to set the timeout. For instance

using(var ts = new TransactionScope(TransactionScopeOption.Required,
                                    TimeSpan.FromMinutes(1)))
{
    using(var ctx = new MyContext())
    {
        // Do stuff.
    }
    ts.Complete(); // Try - catch to catch TimeoutException
}

I'm curious though why you want to set transaction timeout, not command timeout.

6
10/16/2013 6:49:02 PM


Related Questions





Related

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