Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
TransactionAttribute Class

Specifies the type of transaction that is available to the attributed object. Permissible values are members of the TransactionOption enumeration.

Namespace:  System.EnterpriseServices
Assembly:  System.EnterpriseServices (in System.EnterpriseServices.dll)
Visual Basic (Declaration)
<ComVisibleAttribute(False)> _
<AttributeUsageAttribute(AttributeTargets.Class, Inherited := True)> _
Public NotInheritable Class TransactionAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As TransactionAttribute
C#
[ComVisibleAttribute(false)]
[AttributeUsageAttribute(AttributeTargets.Class, Inherited = true)]
public sealed class TransactionAttribute : Attribute
Visual C++
[ComVisibleAttribute(false)]
[AttributeUsageAttribute(AttributeTargets::Class, Inherited = true)]
public ref class TransactionAttribute sealed : public Attribute
JScript
public final class TransactionAttribute extends Attribute

If a transaction type is specified with this attribute, it must not be changed in the COM+ catalog. If the transaction type is changed in the COM+ catalog, the same transaction type must be specified on the component with this attribute.

For more information about using attributes, see Extending Metadata Using Attributes.

The following code example demonstrates the use of the TransactionAttribute to mark a ServicedComponent as transactional.

Visual Basic
<Transaction()>  _
Public Class TransactionalComponent
    Inherits ServicedComponent


    Public Sub TransactionalMethod(ByVal data As String) 

        ContextUtil.DeactivateOnReturn = True
        ContextUtil.MyTransactionVote = TransactionVote.Abort

        ' Do work with data. Return if any errors occur.
        ' Vote to commit. If any errors occur, this code will not execute.
        ContextUtil.MyTransactionVote = TransactionVote.Commit

    End Sub 'TransactionalMethod 
End Class 'TransactionalComponent

C#
[Transaction]
public class TransactionalComponent : ServicedComponent
{

    public void TransactionalMethod (string data)
    {

      ContextUtil.DeactivateOnReturn = true;
      ContextUtil.MyTransactionVote = TransactionVote.Abort;

      // Do work with data. Return if any errors occur.

      // Vote to commit. If any errors occur, this code will not execute.
      ContextUtil.MyTransactionVote = TransactionVote.Commit;

    }

}
Visual C++
[assembly:System::Reflection::AssemblyKeyFile("Transaction.snk")];
[Transaction]
public ref class TransactionalComponent: public ServicedComponent
{
public:
   void TransactionalMethod( String^ data )
   {
      ContextUtil::DeactivateOnReturn = true;
      ContextUtil::MyTransactionVote = TransactionVote::Abort;

      // do work with data
      ContextUtil::MyTransactionVote = TransactionVote::Commit;
   }

};

CPP_OLD
[Transaction]
public __gc class TransactionalComponent : public ServicedComponent {

public:
  void TransactionalMethod (String* data) {

    ContextUtil::DeactivateOnReturn = true;
    ContextUtil::MyTransactionVote = TransactionVote::Abort;

    // do work with data

    ContextUtil::MyTransactionVote = TransactionVote::Commit;

  }

};
System..::.Object
  System..::.Attribute
    System.EnterpriseServices..::.TransactionAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker