The update statement is still committed when scope.Complete () misses.
Oh no! TransacationScope not used 1 .
Autocompletion only works if the connection is open after (or inside) the TransactionScope.
Entering Open
inside a TransactionScope
should fix this problem (even with a manual transaction?), Because the connection will then [usually] automatically start in the context of the surrounding TS.
An existing connection can be credited to the external transaction area: connection.EnlistTransaction(Transaction.Current)
.
Alternatively, TS can be created from an existing transaction, for example. new TransactionScope(transaction)
, which may or may not be useful here.
Creating a manual transaction, if it’s fine, but TS (after getchas is calculated!) Simplifies and simplifies working with transactions .. at least in most cases :)
Happy coding!
1 TS is not used for “update approval”. It will [probably] be used for context.SaveChanges()
, as it will open a new connection, which will then be automatically credited.
I have provided some of the options above, although I'm not sure about a simple "nested" transaction. Seeing that the API (sealed?) Used in context can show more information about constraints / constraints.
user166390
source share