Commit
MSMQTransaction

The Commit method commits the operations requested by the transaction.

Syntax

object.Commit ([fRetaining][, grfTC][, grfRM])
 
Syntax Element Description
object Transaction (MSMQTransaction) object that identifies the transaction.
fRetaining Optional. Reserved by Microsoft DTC.
grfTC Optional. Specifies if the commit is synchronous (default) or asynchronous.

XACTTC_ASYNC: When specified, the call to commit returns as soon as the two-phase commit protocol is initiated.

XACTTC_SYNCPHASEONE: When specified, the call to commit returns after phase one of the two-phase commit protocol.

grfRM Optional. Reserved by Microsoft DTC.

Remarks

Calling Commit does not mean that the operations requested are performed. It only means that MSMQ guarantees that the operations will be performed as an atomic unit. (Commit is a wrapper for lTransaction::Commit. For information on lTransaction::Commit, see the Microsoft Platform SDK.)

An application must call Commit for the messages to be sent. If Commit is not called, the transaction will be terminated when the application exits.

For information on Microsoft® DTC, refer to the Guide to Microsoft Distributed Transaction Coordinator in the Microsoft Platform SDK.

Example

This example starts a transaction, sends two messages, and terminates the transaction.

Dim xdispenser as New MSMQCoordinatedTransactionDispenser
Dim xact as MSMQTransaction

Dim qSend as MSMQQueue                
Dim msg1 as New MSMQMessage
Dim msg2 as New MSMQMessage

'Begins transaction, opening an existing transaction queue.
Set xact = xdispenser.BeginTransaction
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)

'Sends message 1.
msg1.Label = "MyTransaction first message"
msg1.Body = "Message 1 Body"
msg1.Send qSend, xact                    'Associates send with xact.

'Sends message 2.
msg2.Label = "MyTransaction second message"
msg2.Body = "Message 2 Body"
msg2.Send qSend, xact                    'Associates send with xact.

'Commits transaction.
xact.Commit                              'Commits transaction.
 

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in mqoai.h.
  Import Library: Use mqoa.lib.
  Unicode: Defined only as Unicode.