O'Reilly logo

Essential ADO.NET by Bob Beauchemin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.11. Using Transactions

The IDbConnection interface has a single method to begin a local transaction. This method returns an instance of a class that implements IDbTransaction. Classes such as SqlTransaction and OleDbTransaction implement IDbTransaction, which encapsulates operations involving a local transaction such as Commit and Rollback. You can configure the transaction isolation level through an optional parameter of IDbConnection.BeginTransaction. A simple transaction is shown in Listing 3-26.

Listing 3-26. A simple transaction
 SqlConnection sconn = new SqlConnection( "server=(local);uid=sa;pwd=mypw;database=pubs"); SqlCommand cmd = new SqlCommand( "insert jobs values('First', 10, 10)", sconn); SqlTransaction tx = null; try { sconn.Open(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required