I am trying to understand how to ensure that a log entry is only entered onto the file system if a transaction is committed. Please see the code below.
Using (scope As TransactionScope = new TransactionScope())
'write log log file (line 2)'
scope.complete
End Using
At the moment the log file is written to, before the transaction scope is completed.
I have read about the IEnlistmentNotification interface. I know that the SQLConnection class allows for transactions and distributed transactions. Therefore I expected this class to implement IEnlistmentNotification, however it does not. Why doesn’t it?
IEnlistmentNotificationis used by resource managers to participate in transactions but it is not implemented by SQL connections or transactions.If you implement your own transactional resource manager you will implement that interface and use one of the transactions enlistment methods
EnlistDurableorEnlistVolatileto inform the system that you want to participate in this transaction. From this point on you will receive call to the interface that allow you to react to and influence the state of the transaction.If you want to modify files in a transactional way you have to implement or find a resource manger for this purpose. This resource manger will implement
IEnlistmentNotificationand participate in transactions via the mentioned enlistment methods.