Geeks With Blogs
Pradeep Loganathan Distributed

 When transactions span across multiple resources each additional resource increases the chances of failure. For transactions spanning across multiple resources windows uses the MSDTC service. MSDTC coordinates between all the resource managers involved in the transaction using OLE TX .

 

namespace TestTrans1

{

    [Transaction]

    class Worker : ServicedComponent

    {

        public void DoWork()

        {

            string ConnectionString = "connection string";

            System.Data.IDbConnection Conn = new System.Data.SqlClient.SqlConnection(ConnectionString);

            System.Data.IDbCommand Cmd = new System.Data.SqlClient.SqlCommand();

            System.Data.IDbTransaction transaction = null;

           

            try

            {

                Conn.Open();

                Cmd.Connection = Conn;

                Cmd.CommandText = "your_insert_statement";

                Cmd.ExecuteNonQuery();

 

                Cmd.CommandText = "your_other_insert_statement";

                Cmd.ExecuteNonQuery();

 

                ContextUtil.SetComplete();

 

            }

            catch (System.Data.SqlClient.SqlException exception)

            {

                System.Console.WriteLine(exception.ToString());

                ContextUtil.SetAbort();

            }

            finally

            {

                Conn.Close();

            }

        }

    }

Posted on Friday, January 13, 2006 6:11 AM Transactions | Back to top

Copyright © Pradeep Loganathan | Powered by: GeeksWithBlogs.net