TransactionalType TransactionScope over multiple BO's rollback fails?

TransactionalType TransactionScope over multiple BO's rollback fails?

Old forum URL: forums.lhotka.net/forums/t/3133.aspx


cultofluna posted on Tuesday, July 03, 2007

This message concerns post  http://forums.lhotka.net/forums/thread/15688.aspx. I've posted it there as well sorry for that! I wanted to start a new title...

Hello,

I've solved the above problem. I was sloppy on replacing the ADO transactions and try catch structures.

But than I got a new problem :) I'm trying to create a CommandBase object that calls the Save for two BO's.

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Execute()
        {
            _inslag.Status = WmsMutationStatusses.Afgedrukt;
            _inslag.Save();
          
            _locatie.IntakeId = (int)_inslag.SysId;
            _locatie.Save();
        }

Two questions about this structur:

1. Rollback
The first save is no problem. The second BO however has an invalid Stored Procedure name and runs into an error. I now this is an user error, however shouldn't this do a rollback for the first BO as well?

2. Multiple connections
Both BO's open the same connection during the Save. In the forum I read that this means DTC starts a distributed transaction. Is this a problem and perhaps the problem for my first question? I can't pass the connection for two separate BO's can I?

Any thoughts?

Regards,


cultofluna replied on Tuesday, July 03, 2007

Hmmm. i've found that adding enlist=false to the connstring does not really help in using the transactions the dtc way?

cultofluna replied on Tuesday, July 03, 2007

I've changed the connstring and the dtc is responding, however not the right way... after approx two minutes I receive the following exception:

Print is niet gelukt. DataPortal.Update mislukt (Csla.DataPortalException: DataPortal.Update mislukt (System.Transactions.TransactionException: The transaction has already been implicitly or explicitly committed or aborted. ---> System.Runtime.InteropServices.COMException (0x8004D00E): De transactie is al impliciet of expliciet doorgevoerd of afgebroken. (Exception from HRESULT: 0x8004D00E)

Does the use of several Transactions interrupt the proces?

cultofluna replied on Tuesday, July 03, 2007

Ok, so I found the problem... the commandbase that calls the Save for both the BO's has a transaction as well as the two BO's....

It seems like the Transaction is not shared or something...

Any thoughts?


cultofluna replied on Tuesday, July 03, 2007

even if I get this stuff to work, it seems like using SQL2K with transactionscope isn't a smart thing to do as it will always use distributed transactions...

however, how DO I handle one transaction for two BO's?

Skafa replied on Thursday, July 05, 2007

*bump*

I would like to know how this can be done too...

cultofluna replied on Thursday, July 05, 2007

Hello Skafa,

It took me a while to figure out that getting TransactionScope to work with SQL2K is hard to do. However simply using ADO transactions does the trick perfectly. Please take a look at my post at the following address:

http://forums.lhotka.net/forums/thread/15835.aspx

This works great for me. Please let me know if you have any problems getting it to work.

Regards,

tetranz replied on Thursday, July 05, 2007

cultofluna:
even if I get this stuff to work, it seems like using SQL2K with transactionscope isn't a smart thing to do as it will always use distributed transactions...

Here's a way of overcoming that. It works pretty well for me.
http://blogs.msdn.com/florinlazar/archive/2005/09/29/475546.aspx

I found it via Rocky's suggestion here:
http://lhotka.net/Article.aspx?area=4&id=39c79955-ddc9-42c7-a657-d5c2ed49975e

Ross

cultofluna replied on Thursday, July 05, 2007

Hello Ross,

Thanks for that. I've found these as well, however I was having a hard time getting it to work the way it should as the DTC was getting activated, probably because not only the CommandBase but the BO's themselves started an own connection and transaction.
After several hours of frustation I quit using it and started the ADO version based on another post of Rocky (please refer to the post in my previous message, as I dont have it at hand right now!)
What I like about the ADO solutions is that's it's pretty lightweight, transparant and easy to use. However when I move to SQL2K5 I'll try again :)

Regards,

Copyright (c) Marimer LLC