Exemplo n.º 1
0
        public static void DemonstrateIsolationLevel(String connString, IsolationLevel level)
        {
            // Before connect the database, recreate the table.
            OperateDatabase.CreateTable(connString);
            DemonstrateIsolationLevel(connString, level, DirtyReadThreads.DirtyReadFirstThread, DirtyReadThreads.DirtyReadSecondThread);
            DisplayData(connString);
            Console.WriteLine();

            OperateDatabase.CreateTable(connString);
            DemonstrateIsolationLevel(connString, level, NonrepeatableReadThreads.NonrepeatableReadFirstThread, NonrepeatableReadThreads.NonrepeatableReadSecondThread);
            Console.WriteLine();

            OperateDatabase.CreateTable(connString);
            DemonstrateIsolationLevel(connString, level, PhantomReadThreads.PhantomReadFirstThread, PhantomReadThreads.PhantomReadSecondThread);
            Console.WriteLine();
        }
Exemplo n.º 2
0
        // Demonstrates the difference between the Serializable and Snapshot transaction
        public static void DemonstrateBetweenSnapshotAndSerializable(String connString)
        {
            OperateDatabase.CreateTable(connString);

            Console.WriteLine("Exchange Vaules in the Snapshot transaction:");
            DemonstrateIsolationLevel(connString, IsolationLevel.Snapshot,
                                      ExchangeValuesThreads.ExchangeValuesFirstThread,
                                      ExchangeValuesThreads.ExchangeValuesSecondThread);
            DisplayData(connString);
            Console.WriteLine();

            Console.WriteLine("Cannot Exchange Vaules in the Serializable transaction:");
            OperateDatabase.CreateTable(connString);
            DemonstrateIsolationLevel(connString, IsolationLevel.Serializable,
                                      ExchangeValuesThreads.ExchangeValuesFirstThread,
                                      ExchangeValuesThreads.ExchangeValuesSecondThread);
            DisplayData(connString);
        }
Exemplo n.º 3
0
        internal static void Main(string[] args)
        {
            String connString = "Data Source=(local);Initial Catalog=master;Integrated Security=True;Asynchronous Processing=true;";

            OperateDatabase.CreateDatabase(connString);
            Console.WriteLine();

            Console.WriteLine("Demonstrate the ReadUncommitted transaction: ");
            TransactionIsolationLevels.DemonstrateIsolationLevel(connString,
                                                                 System.Data.IsolationLevel.ReadUncommitted);
            Console.WriteLine("-----------------------------------------------");

            Console.WriteLine("Demonstrate the ReadCommitted transaction: ");
            TransactionIsolationLevels.DemonstrateIsolationLevel(connString,
                                                                 System.Data.IsolationLevel.ReadCommitted);
            Console.WriteLine("-----------------------------------------------");

            Console.WriteLine("Demonstrate the RepeatableRead transaction: ");
            TransactionIsolationLevels.DemonstrateIsolationLevel(connString,
                                                                 System.Data.IsolationLevel.RepeatableRead);
            Console.WriteLine("-----------------------------------------------");

            Console.WriteLine("Demonstrate the Serializable transaction: ");
            TransactionIsolationLevels.DemonstrateIsolationLevel(connString,
                                                                 System.Data.IsolationLevel.Serializable);
            Console.WriteLine("-----------------------------------------------");

            Console.WriteLine("Demonstrate the Snapshot transaction: ");
            OperateDatabase.SetSnapshot(connString, true);
            TransactionIsolationLevels.DemonstrateIsolationLevel(connString,
                                                                 System.Data.IsolationLevel.Snapshot);
            Console.WriteLine("-----------------------------------------------");

            Console.WriteLine("Demonstrate the difference between the Snapshot and Serializable transactions:");
            TransactionIsolationLevels.DemonstrateBetweenSnapshotAndSerializable(connString);
            OperateDatabase.SetSnapshot(connString, false);
            Console.WriteLine();
        }