In ADO.NET there is a hard-coded system-wide limit for transaction set to 10 minutes. You cannot change it just like that in your web.config or App.config. You can change it in machine.config though. First, where are the machine configs?
For 32 Bits: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machie.config
For 64 Bits: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
Now, how to change it?
Just add the following (for 12 hours):
1 2 3 |
< system.transactions> < defaultSettings timeout="12:00:00" /> < /system.transactions> |
You can also try to change it with reflection:
1 2 3 4 5 6 7 8 9 10 11 |
private void SetTransactionManagerField(string fieldName, object value) { typeof(TransactionManager).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, value); } public TransactionScope CreateTransactionScope(TimeSpan timeout) { SetTransactionManagerField("_cachedMaxTimeout", true); SetTransactionManagerField("_maximumTimeout", timeout); return new TransactionScope(TransactionScopeOption.RequiresNew, timeout); } |
Also, something like this should also work if you use it in console app before running any transaction:
1 2 3 4 5 6 7 |
var machineSettings = (System.Transactions.Configuration.MachineSettingsSection)ConfigurationManager.GetSection("system.transactions/machineSettings"); var readOnly = (typeof(ConfigurationElement)).GetField("_bReadOnly", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); readOnly.SetValue(machineSettings, false); machineSettings.MaxTimeout = TimeSpan.MaxValue; using (var t = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(12,0,0))) { } |
So many ways to change a value which should be configurable in code in the first place, however, sometimes Microsoft just forces you to google some weird stuff on the Internet. As a homework, try to find and download WinDBG.exe in 5 minutes (without downloading whole Windows SDK or anything similar having 300MB of tools when you need just one binary).