How to send a data recordset using Microsoft Message Queue Server message body (179575)



The information in this article applies to:

  • Microsoft Message Queue Server (MSMQ) 1.0
  • Remote Data Service for ADO 1.5
  • Remote Data Service for ADO 2.0
  • Remote Data Service for ADO 2.1 SP2

This article was previously published under Q179575

SUMMARY

Using Microsoft Message Queue Server (MSMQ) and Microsoft Remote Data Service (RDS), you can send and receive a data recordset using MSMQ message body.

MORE INFORMATION

Follow these steps to run the code example below:
  1. Install Microsoft Data Access Components (MDAC) from this Web address:
  2. Add references to Microsoft Message Queue Server (MSMQ), the ActiveX Data Objects (ADO) Object Library, and Remote Data Service (RDS) Object Libraries in your Visual Basic project. The sample opens a connection to the SQL Server pubs database on your computer. You can modify the code to use other databases:

    Note You must change Username=<username> and PWD=<strong password> to the correct values before you run this code. Make sure that Username has the appropriate permissions to perform this operation on the database.
         Private Sub Form_Load()
         Dim rsSend As ADOR.Recordset
         Dim rsReceive As ADOR.Recordset
         Dim sql As String
         Dim RDS As Object
             
         Dim dataFactory As Object
    
         Dim qinfo As New MSMQQueueInfo
         Dim mSend As New MSMQMessage
         Dim mReceive As MSMQMessage
         Dim qSend As MSMQQueue
         Dim qReceive As MSMQQueue
    
         qinfo.PathName = ".\RecordsetQ"
         qinfo.Label = "My Recordset Queue"
            
         ' ignore if the queue already exists
         On Error Resume Next
         qinfo.Create
         On Error GoTo 0
    
         Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
         
         Set RDS = CreateObject("RDS.DataSpace")
             
         Set dataFactory = RDS.CreateObject("RDSServer.DataFactory", _
                                            "http://localhost")
    
         sql = "select * from authors"
         Set rsSend = dataFactory.query("driver={SQL Server};SERVER=(local);" & _ 
                                        "database=pubs;Username=<username>;PWD=<strong password>;", sql)
             
          mSend.Label = "Testing Recordset"
          mSend.Body = rsSend
          mSend.Send qSend
          qSend.Close
    
          MsgBox "Message sent with Recordset"
            
          Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
             
          Set mReceive = qReceive.Receive
          Set rsReceive = mReceive.Body
             
          Debug.Print rsReceive(0).Value ' print column 1
          Debug.Print rsReceive(1).Value ' print column 2
          Debug.Print rsReceive(2).Value ' print column 3
             
          rsReceive.MoveNext
             
          Debug.Print rsReceive(0).Value ' print column 1
          Debug.Print rsReceive(1).Value ' print column 2
          Debug.Print rsReceive(2).Value ' print column 3
          
     End Sub
    					

REFERENCES

Microsoft Message Queue Server SDK Help.

Remote Data Service (RDS) documentation located at this Web address:

Modification Type:MajorLast Reviewed:8/29/2006
Keywords:kbDatabase kbhowto KB179575