using System;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;
using System.Collections.Generic;
using System.Text;

namespace ImplicitTransaction
{
   class Program
   {
      static void Main(string[] args)
      {
         using (TransactionScope scope = new TransactionScope())
         {
            using (SqlConnection conn = new SqlConnection(
              "data source=localhost; initial catalog=SampleDB; integrated security=SSPI;"))
            {
               conn.Open();
               SqlCommand cmd = conn.CreateCommand();
               cmd.CommandText = "DELETE Customers";

               cmd.ExecuteNonQuery();

               // to spowoduje zgłoszenie wyjątku dzielenia przez zero
               // zapobiegającego przed wywołaniem scope.Complete()
               int z = 12;
               int y = 1;
               y -= 1;
               Console.WriteLine("{0}", z / y);
            }
            scope.Complete();
         }
      }
   }
}
