Microsoft KB Archive/179575

= How to send a data recordset using Microsoft Message Queue Server message body =

Article ID: 179575

Article Last Modified on 2/16/2007

-

APPLIES TO


 * Microsoft Message Queue Server 1.0
 * Microsoft Remote Data Services 1.5
 * Remote Data Service for ADO 2.0
 * Microsoft Remote Data Services 2.1

-



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:  Install Microsoft Data Access Components (MDAC) from this Web address:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx

  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= and PWD= 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= ;PWD= ;", 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 

