• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

ContextUtil class and com

I was wondering is there a way to do transactions in .net

I was at a microsoft .net seminar and asked them doing transactions like com+ but not actully using com services

the reason why is the database is mysql.  They said use the distributor transaction coordinator class.

If you have an example in how to do this it would be greatly appreciated.


0
genesisproject
Asked:
genesisproject
1 Solution
 
Bob LearnedCommented:
Are you talking about transactions in ADO.NET?

Bob
0
 
123654789987Commented:
Try the following link

The Distributed Transaction Coordinator (DTC) is the Transaction Processing monitor for Microsoft Windows 2000.


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnettransact1.asp

Also see this explanation:

The COM+ BYOT feature allows COM+ components to set a preexisting Microsoft Distributed Transaction Coordinator (DTC) or Transaction Internet Protocol (TIP) transaction as the transaction property of a new component's context. This allows COM+ components to be associated with transactions whose lifetimes are controlled by a transaction processing monitor, object transaction service, or database management system. BYOT is also useful in integrating with transactions coordinated by TIP.

Note   Automatic transactions, rather than BYOT transactions, are the preferred programming model for writing business components. BYOT transactions must be used with caution. In certain situations, they can result in a transaction spanning multiple synchronization domains (that is, allowing parallelism with a transaction).
The BYOT class exposes two methods: CreateWithTransaction and CreateWithTipTransaction. The following example shows how to create an object that uses the transaction from another object.

BYOT Demonstration

[Visual Basic]
Imports System
Imports System.Reflection
Imports System.EnterpriseServices

<assembly: AssemblyKeyFile("BYOTDemo.snk")>

Public Class Base
      Inherits ServicedComponent
      Public Readonly Property Transaction() as Object
        Get
            Return ContextUtil.Transaction
        End Get
      End Property
End Class

<Transaction()> Public Class CTransaction1
Inherits Base
' Insert your transaction logic here.
End Class

<Transaction()> Public Class CTransaction2
Inherits Base
' Insert your transaction logic here.
End Class

Class BYOTDemonstration
      Public Shared Sub Main()
            ' Create a transactional object, and then get its
            ' transaction.
            Dim tx1 as New CTransaction1
            Console.WriteLine("Created transaction1.")
            Dim tx as Object = tx1.Transaction
            Console.WriteLine("Got the transaction of transaction1.")      
            Dim tx2 as CTransaction2 = ctype(BYOT.CreateWithTransaction(tx, _ gettype(CTransaction2)),CTransaction2)
            Console.WriteLine("Created transaction2 with the _
            transaction of transaction1.")
            End Sub
End Class
0
 
genesisprojectAuthor Commented:
thanks for the quick response so with byot how would I do a simple transaction like this
'this would be in my business logic

Dim client as new Demo.Client
Dim guardian as New Demo.Guardian

the client and guardian class are my calls to the database Data Access Layer



this is the transaction part


  client.AddClient(addData.Tables(0).Row(0))

guardian.addGuardian(addData.Tables(0).Row(0))






0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now