using System.Transactions; using(var scope = new TransactionScope()) { // your transactional code here }
using System.Transactions; var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.Serializable, Timeout = TimeSpan.FromSeconds(30) }; using(var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { // your transactional code here }
using System.Transactions; var transaction = Transaction.Current; using(var conn = new SqlConnection("connectionString")) { conn.Open(); using(var cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO myTable VALUES (@param1, @param2)"; cmd.Parameters.AddWithValue("@param1", "value1"); cmd.Parameters.AddWithValue("@param2", "value2"); // enlist in the current transaction cmd.Transaction = transaction; cmd.ExecuteNonQuery(); } }Package library: System.Transactions (included in the .NET Framework)