//assuming connection has already been established using (var transaction = connection.BeginTransaction()) { //transaction logic here transaction.Commit(); }
using (var transaction = connection.BeginTransaction()) { try { //perform transaction here transaction.Save("savepoint1"); //perform other transactions here transaction.Save("savepoint2"); //perform additional transactions here transaction.Commit(); } catch(Exception ex) { transaction.Rollback("savepoint1"); transaction.Rollback("savepoint2"); } }This code example demonstrates how to use save points to create nested transactions. IDbTransaction saves a save point and makes additional changes to the database. If the nested transaction fails, it rolls back to the last save point instead of rolling back the entire transaction. The package library that provides IDbTransaction is System.Data. In this package, types like IDbConnection, IDbCommand, IDbTransaction, and their implementation classes like SqlConnection, SqlCommand, etc. are defined and available to use in C# programming.