Visual Basic Code Example: Creating a Transactional Queue
This example provides a private function that creates a public or private transactional queue based on a given queue path name.
|Public queues cannot be created if there is no connection to the directory service. This restriction applies to dependent client computers, independent client computers that are working offline, and Message Queuing servers that have routing services enabled (for MSMQ 1.0, these servers are referred to as FRS servers).|
The following procedure shows how the private function creates a transactional queue.
To create a transactional queue
Declare the MSMQQueueInfo variable for the queue.
Create a new MSMQQueueInfo object and assign it to the variable.
Set the MSMQQueueInfo.PathName property to the UNC or DNS path name of the queue.
The following are examples of UNC path names that can be used to create public and private queues for the local computer.
.\testqueue ' Public queue path name. .\PRIVATE$\testqueue ' Private queue path name.
|For Message Queuing dependent clients, the local computer is the client's supporting server.|
Set optional queue properties. This example also specifies the label of the queue using MSMQQueueInfo.Label.
Call MSMQQueueInfo.Create with the IsTransactional parameter of MSMQQueueInfo.Create set to True.
This code example contains no version-specific Message Queuing calls.
Sub CreateMyXactQueue( strPathname As String ) Dim qinfo As MSMQQueueInfo Set qinfo = New MSMQQueueInfo qinfo.PathName = strPathname qinfo.Label = "TestQueue" On Error GoTo ErrorHandler qinfo.Create IsTransactional:=True MsgBox "Created Queue." Exit Sub ErrorHandler: MsgBox "Error " + Hex(Err.Number) + " was returned." _ + Chr(13) + Err.Description End Sub