Using Transactions

As shown in Figure 8.1, providers can support transactions that implement the IDbTransaction interface and that are associated to the connection class. Both the SqlClient and OleDb providers include transaction objects that are created using the BeginTransaction method of the appropriate connection class. Transactions are obviously very useful for making sure that multiple commands (statements) executed against a single data store are treated as a logical unit of work. In that way, if one of the statements fails, all of them can be rolled back (undone). Likewise, if all of them succeed, they will all be committed (made permanent) on the data store.

Note

As you'll see momentarily, using transactions necessarily implies that ...

Get Sams Teach Yourself ADO.NET in 21 Days 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.