Transactions and System.Transactions

While you can do simple transaction support with ADO.NET, Visual Basic includes a set of classes specifically designed for working with transactions: the System.Transactions namespace. As the name implies, these classes allow you to define and work with transactions in your code.

You may well be wondering at this point why you need two methods of working with transactions. The classes of System.Transaction, particularly the Transaction class itself, abstract the code from the resource managers participating in the transaction. Transactions in ADO.NET are specific to each database you may access. There is no unified method of creating a transaction, nor is there a standard way of sharing a database transaction across multiple databases or other transaction supporters. The Transaction class provides for these limitations, and can coordinate multiple resource managers itself.

The classes of System.Transaction also provide the means to create your own resource managers. These resource managers may then participate in transactions. At first, you may balk at this prospect, wondering how you could write something that manages all the details of a transactional data store. Aren't the details enormous? Fortunately, the classes make it easy to enlist in a transaction and report on your results.

Creating Transactions

System.Transaction supports two means of working with transactions: implicit and explicit. With implicit transactions, you define a boundary ...

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.