none
Transactions promote to distributed transactions only on Windows Server 2008 RRS feed

  • Question

  • The following small .NET 2.0 console application uses explicit transactions to execute two sqlcommands each within its own transaction using the same sqlconnection. This works perfectly on Windows Server 2003, Windows XP and on Windows Vista without DTC (Distributed Transaction Coordinator) running, but on Windows Server 2008 it throws a SqlException if the DTC service is not running. Apparently, the following code doesn't require DTC on any OS except for Windows Server 2008. Does anybody know what is causing this behavior?

     

    class Program

    {

      static void Main(string[] args)

      {

        SqlConnectionStringBuilder oBuilder = new SqlConnectionStringBuilder();

        oBuilder.InitialCatalog = "database";

        oBuilder.DataSource = "localhost";

        oBuilder.IntegratedSecurity = true;

        SqlConnection oConnection = new SqlConnection(oBuilder.ToString());

        oConnection.Open();

     

        Console.WriteLine("Transaction 1...");

        CommittableTransaction oTransaction = new CommittableTransaction();

        oConnection.EnlistTransaction(oTransaction);

        SqlCommand oCommand = new SqlCommand("UPDATE tblUSERS SET Tag = '<root/>' WHERE Name = 'Administrator'", oConnection);

        oCommand.ExecuteNonQuery();

        oTransaction.Commit();

     

        Console.WriteLine("Transaction 2...");

        oTransaction = new CommittableTransaction();

        oConnection.EnlistTransaction(oTransaction);

        oCommand = new SqlCommand("UPDATE tblUSERS SET Tag = '<root5/>' WHERE Name = 'Administrator'", oConnection);

        oCommand.ExecuteNonQuery();

        oTransaction.Commit();

     

        Console.WriteLine("Closing...");

        oConnection.Close();

      }

    }

    Friday, January 4, 2008 3:36 PM

Answers

All replies

  • Something I forgot to mention. Don't know if it is related to my problem though. The Windows Server 2003, XP and Vista machines that I've tried on are all 32-bit Windows. The Windows Server 2008 RC1 server is a 64-bit Windows.

    Friday, January 4, 2008 5:05 PM
  • I am assuming since it is beta software you have not installed the .NET 2.0 X64 version which also installs the .NET 2.0 X86 version which implements System.Transaction.  The reason Visual Studio even 2008 is a 32bits application which supports 64bits development which means you need to install all you need to access 32bit development so you can access it in WOW64.  Win2003 X64 in some cases mostly web application require new install of the X64.NET 2.0 framework so the X86 .NET 2.0 framework will be installed.
    Friday, January 4, 2008 9:41 PM
  • There's no need to manually install .NET 2.0 x86 or x64 on Windows Server 2008. This is installed by default. I can confirm that .NET 2.0 applications run perfectly on Windows Server 2008, even with transactions. They run in 64-bit as they are compiled for Any Platform.

     

    The only difference is that on Windows Server 2008, starting a second CommittableTransaction on the same SqlConnection automatically promotes this second transaction to a distributed transaction. This should not happen as it does not happen on any other OS.

     

    Michael

    Saturday, January 5, 2008 12:16 PM
  • EDIT

     

    Win2003 was released long before .NET 2.0 but even today I still help users to install the .NET 2.0 x64 in x64 boxes because 32bits appiclations are not running.  And compiling code in AnyCPU just makes an application mixed platform not 64bits because most pure 64bits development is in SDK code not application because Microsoft says their partners are in 32bits.   You could post at the transaction programming forum here with code so they can work with the Windows team.  You building to target AnyCPU when you are developing in 32bits could actually be the cause of the problem. 

     

    Saturday, January 5, 2008 2:57 PM
  •  

    In case anybody else has this problem... This problem was caused by a bug in Windows Server 2008 RC1 which apparently has been fixed in RTM. More information can be found on http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2818604&SiteID=1&mode=1.
    Saturday, February 9, 2008 5:05 PM