Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

Using Transactions with the Explicit API



The�CreateTx sample demonstrates how to create a simple transaction. This sample creates a transaction instance in various ways, based on a command line argument the user supplies. No actual transacted work will be done, but the user can choose to commit or abort this empty transaction after it is created.

		

 class CreateTx
    {
        static void Main(string[] args)
        {
            ITransactionManager tm = null;
            ICommittableTransaction tx = null;
            TransactionOptions options = new TransactionOptions();


			try
            {
                switch(args[0])
                {
                    case "1":
                        tx = Transaction.Create();
                        break;
                    case "2":
                        options.IsolationLevel = IsolationLevel.ReadCommitted;
                        options.Timeout = new TimeSpan(0, 0, 30);
                        tx = Transaction.Create(options);
                        break;
                    case "3":
                        tm = TransactionManager.DefaultTransactionManager;
                        tx = tm.CreateTransaction();
                        break;
                    case "4":
                        options.IsolationLevel = IsolationLevel.ReadCommitted;
                        options.Timeout = new TimeSpan(0, 0, 30);
                        tm = TransactionManager.DefaultTransactionManager;
                        tx = tm.CreateTransaction(options);
                        break;
                }
                ...
                // Commit the transaction
                tx.Commit();
            }
        }
C#


The following example shows how to create a transaction using the explicit API No Source or Sample to display.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.