Sending Messages Using an MS DTC External Transaction

To send a message within an MS DTC external transaction, the MSMQCoordinatedTransactionDispenser is used to create the transaction object. After the transaction object is created, make sure it is referenced in the call to Send.

To send a message using an external transaction
  1. Specify the type of transaction dispenser you want to use. For external transactions, specify the MSMQCoordinatedTransactionDispenser object.
    Dim xdispenser as New MSMQCoordinatedTransactionDispenser
    
  2. Call BeginTransaction.
    Set xact = xdispenser.BeginTransaction
    
  3. Open the queue with send access.
    Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
    
  4. Create and send the message. Make sure the call to Send is associated with the transaction.
    msg.Label = "MyTransaction message"
    msg.Body = "Message 1 Body"
    msg.Send qSend, xact                    'Associates send with xact.
     

Example

This example sends a single message within an external transaction.

Dim xdispenser as New MSMQCoordinatedTransactionDispenser
Dim xact as MSMQTransaction

Dim qSend as MSMQQueue                
Dim msg as New MSMQMessage

Set xact = xdispenser.BeginTransaction

'Assumes queue already exists and is transactional.
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
msg.Label = "MyTransaction message"
msg.Body = "Message 1 Body"
msg.Send qSend, xact                     'Associates send with xact.

© 1997 by Microsoft Corporation. All rights reserved.