Using code like
using (var tran = Ctxt.Database.BeginTransaction()) {
How can I set a value for the transaction timeout ?
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.