BeginTransaction
MSMQCoordinatedTransactionDispenser MSMQTransactionDispenser

The BeginTransaction method creates a new MSMQ transaction object. It returns an MSMQTransaction object that is used when sending and retrieving messages during the transaction.

Syntax

Set object1 = object2.BeginTransaction
 
Syntax Element Description
object1 Transaction (MSMQTransaction) object that identifies the transaction.
object2 Transaction dispenser (MSMQTransactionDispenser or MSMQCoordinatedTransactionDispenser) object that creates the transaction.

Return Values

MSMQTransaction object that identifies the transaction.

Remarks

The MSMQTransaction object returned by BeginTransaction must be associated with all transaction queues and messages associated with this transaction. However, this does not mean that a transaction queue associated with this transaction cannot be used by other transactions. A single transaction queue can be associated with any number of transactions.

Example

This example starts a transaction and sends two messages.

Dim xdispenser as New MSMQCoordinatedTransactionDispenser
Dim xact as MSMQTransaction

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

Set xact = xdispenser.BeginTransaction

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

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

xact.Commit
 

See Also

MSMQTransaction


© 1997 by Microsoft Corporation. All rights reserved.