Search code examples
c#.nettransactionstransactionscope

C# - System.Transactions.TransactionScope


I was curious about the TransactionScope class.

For the most part, I assume it was intended for database connections (which is what I've used it for).

My question, is can you put any code in the using-block of a TransactionScope to make it transactional? MS documentation is not clear on this.

If it can be used to make code other than database connections transactional, which ones are supported? It would seem crazy to me if it could make System.IO.File operations transactional.


Solution

  • TransactionScope is not only for the databases. Every component that implements IEnlistmentNotification interface can participate in two-phase commit of the transaction scope.

    Here is an example of transactional in-memory storage: http://www.codeproject.com/KB/dotnet/Transactional_Repository.aspx

    Also, I'm not sure if there are components in .NET for transactional file IO, but it is pretty easy to implement such component - latest OS like Vista and Windows Server 2008 have support for transaction file IO.