c# - TransactionScope not rolling back although no complete() is called -
i'm using transactionscope rollback transaction fail
bool errorreported = false; action<importerrorlog> newerrorcallback = e => { errorreported = true; errorcallback(e); }; using (var transaction = new transactionscope()) { foreach (importtaskdefinition task in taskdefinition) { loader.load(streamfile, newerrorcallback, task.destinationtable, processingtaskid); } if (!errorreported) transaction.complete(); }
i'm sure there no transactionscope started ahead or after code. i'm using entity framework insert in db.
regardless state of errorreported
transaction never rolled in case of error.
what missing ?
transactionscope
sets transaction.current
. that's does. wants transacted must @ property.
i believe ef each time connection opened reason. probably, connection open when scope installed.
open connection inside of scope or enlist manually.
ef has nasty "design decision": default opens new connection each query. causes distributed transactions in non-deterministic way. sure avoid that.
Comments
Post a Comment