SubSonic Forums
All Your Database Are Belong To Us

Transaction Scope and MSDTC

Latest post 10-20-2008 3:49 PM by spookytooth. 8 replies.
  • 01-09-2008 1:00 PM

    • mm
    • Top 500 Contributor
    • Joined on 10-18-2007
    • Posts 9

    Transaction Scope and MSDTC

    Hi all, I've been having problems when trying to perform some transactional operation in my app. I'm trying to perform transaction by using TransactionScope in a remote database.  The following is the code that I'm using:

    TransactionOptions tranOptions = GlobalUtilities.getTransactionOptions();
    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tranOptions))
    using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())

     {
         ActiveController<Company, CompanyCollection>.Save(item, username);    
         ts.Complete();

    }

     But this is not working since it giving me an exception claiming that the MSDTC is not active.  I do not want to use MSDTC since it is not a distributed query.

    Any Ideas?? Thanks! 

     

  • 01-09-2008 10:20 PM In reply to

    Re: Transaction Scope and MSDTC

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 01-10-2008 9:33 AM In reply to

    • mm
    • Top 500 Contributor
    • Joined on 10-18-2007
    • Posts 9

    Re: Transaction Scope and MSDTC

    Thanks for the fast reply! The code I posted works when DTC is enabled.

    The code from the example from the link you posted does not raise any exception when  DTC is disabled (I replaced ts.Close() with ts.Complete() ) but transactions are not working and all changes are saved no matter what.

    Has anybody got this to work?

     

    Thanks!! 

     


  • 01-10-2008 3:50 PM In reply to

    Re: Transaction Scope and MSDTC

    I think you need to wrap the second using inside the first:

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tranOptions)){
    using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())

     {
         ActiveController<Company, CompanyCollection>.Save(item, username);    
         ts.Complete();

    }

     This might be a typo on our docs.

     

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

  • 01-11-2008 10:10 AM In reply to

    • mm
    • Top 500 Contributor
    • Joined on 10-18-2007
    • Posts 9

    Re: Transaction Scope and MSDTC

    Thanks for the response Rob, however, that code only works when DTC is enabled. I don't know why a query as simple as that is trying to escalate and use DTC. Should it? Am I missing something here? Maybe I'm doomed to enabling DTC service when using TransactionScope.

    What do you think?

    Thanks!!! 

  • 01-11-2008 2:07 PM In reply to

    Re: Transaction Scope and MSDTC

    This forces the transaction to not use DTC - have you tried it?

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

  • 01-11-2008 2:50 PM In reply to

    • mm
    • Top 500 Contributor
    • Joined on 10-18-2007
    • Posts 9

    Re: Transaction Scope and MSDTC

    This code:

     TransactionOptions tranOptions = new TransactionOptions();
    tranOptions.IsolationLevel = IsolationLevel.Serializable;
    tranOptions.Timeout = new TimeSpan(0,0,10);

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tranOptions))
    {
        using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
        {
            ActiveController<Company, CompanyCollection>.Save(item, username);
            ts.Complete();
        }
    }

    When executes it enables DTC (if it was manually disabled) and gives this exception.

    [TransactionManagerCommunicationException: Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.]
     

  • 02-17-2008 9:48 PM In reply to

    • mm
    • Top 500 Contributor
    • Joined on 10-18-2007
    • Posts 9

    Re: Transaction Scope and MSDTC

    Well today I run into some interesting information here  where it basically says that Distributed Transactions over SQL Server 2000 ALWAYS escalate to using DTC. If this is true then I'm doomed since I am using 2000... 

    Anyway thanks everybody for helping me with this!!

    Filed under:
  • 10-20-2008 3:49 PM In reply to

    Re: Transaction Scope and MSDTC

     mm - you need to wrap the "using TransactionScope" INSIDE the "using SharedDbConnectionScope" - this forces non-elevation. So the code in your sample above is reversed.

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

Page 1 of 1 (9 items) | RSS