Passing DBTransaction between functions in Bus Layer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chevron Boyde

    Passing DBTransaction between functions in Bus Layer

    Hi all

    I have a function setup in my Bus Logic Layer similar to the following
    function ProcessOrders
    function InsertOrder
    function InsertOrderItem s

    I need to be make sure all functions use the same Transaction (Enterprise
    Lib DbTransaction object) between method calls.

    How shoudl I lat this out?

    Cheers

    S

  • Marc Gravell

    #2
    Re: Passing DBTransaction between functions in Bus Layer

    The most practial solution would be TransactionScop e; apart from not
    requiring any work, any other code that uses suitable connections can
    also enlist, it supports distributed transactions, and nesting is
    supported (as are isolation levels, non-transactional blocks, etc).

    Example: add a reference to System.Transact ions, then

    // cheesy example ;-p
    static void Transfer(int fromAccount, int toAccount, int amount)
    {
    using (TransactionSco pe tran = new TransactionScop e())
    {
    Debit(fromAccou nt, amount);
    Credit(toAccoun t, amount);
    tran.Complete() ;
    }
    }

    On SQL2000, it uses DTC from the outset (since SQL2000 transactions
    aren't promoteable) - but on SQL2005 it uses the "LTM" (lightweight
    transaction manager) to start with a SQL transaction, and promote that
    to a DTC transaction if necessary (for instance you start talking to a
    second server...).

    Marc

    Comment

    • Chevron Boyde

      #3
      Re: Passing DBTransaction between functions in Bus Layer

      thanks marc!

      "Marc Gravell" <marc.gravell@g mail.comwrote in message
      news:5aa8fd1e-a364-480e-9578-7d4f25fb8126@a2 3g2000hsc.googl egroups.com...
      The most practial solution would be TransactionScop e; apart from not
      requiring any work, any other code that uses suitable connections can
      also enlist, it supports distributed transactions, and nesting is
      supported (as are isolation levels, non-transactional blocks, etc).
      >
      Example: add a reference to System.Transact ions, then
      >
      // cheesy example ;-p
      static void Transfer(int fromAccount, int toAccount, int amount)
      {
      using (TransactionSco pe tran = new TransactionScop e())
      {
      Debit(fromAccou nt, amount);
      Credit(toAccoun t, amount);
      tran.Complete() ;
      }
      }
      >
      On SQL2000, it uses DTC from the outset (since SQL2000 transactions
      aren't promoteable) - but on SQL2005 it uses the "LTM" (lightweight
      transaction manager) to start with a SQL transaction, and promote that
      to a DTC transaction if necessary (for instance you start talking to a
      second server...).
      >
      Marc

      Comment

      • Marc Gravell

        #4
        Re: Passing DBTransaction between functions in Bus Layer

        No problem; for more info, there are lots of links from here:

        [don't ask me why it has the same VB example twice, yet no C#]

        Alternatively, just use your favorite search engine...

        Marc

        Comment

        Working...