Data recordsets can be sent and retrieved using a combination of MSMQ and Microsoft Remote Data Service (RDS).
Note RDS is used to transport Active Data Object recordsets from a server to a client computer. The resulting recordset is cached on the client computer and disconnected from the server.
qinfo.PathName = ".\RecordsetQueue2"
qinfo.Label = "My Recordset Queue"
On Error Resume Next 'Ignore if queue already exists.
qinfo.Create
On Error Goto 0 'Reset error handler.
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
sql = "select * from authors"
Set rsSend = dataFactory.Query("driver={SQL Server};server=.;database=pubs;uid=sa;pwd=", sql)
mSend.Label = "Testing Recordset"
mSend.Body = rsSend
mSend.Send qSend
qSend.Close
Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set mReceive = qReceive.Receive
Set rsReceive = mReceive.Body
The following example creates an ADO recordset, sends the message to a destination queue, and retrieves the message and places it in a new recordset.
Option Explicit
Dim rsSend As ADODB.Recordset
Dim rsReceive As ADODB.Recordset
Dim dataFactory As New RDSServer.DataFactory
Dim sql As String
Dim qinfo As New MSMQQueueInfo
Dim qSend As MSMQQueue
Dim qReceive As MSMQQueue
Dim mSend As New MSMQMessage
Dim mReceive As MSMQMessage
Private Sub Form_Click()
'*******************************************************************
' Create a destination queue and open it with SEND access.
'*******************************************************************
qinfo.PathName = ".\RecordsetQueue2"
qinfo.Label = "My Recordset Queue"
On Error Resume Next 'Ignore if queue already exists.
qinfo.Create
On Error Goto 0 'Reset error handler.
Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
'*******************************************************************
' Create an ADO recordset.
'*******************************************************************
sql = "select * from authors"
Set rsSend = dataFactory.Query("driver={SQL Server};server=.;database=pubs;uid=sa;pwd=", sql)
'*******************************************************************
' Create a message and send it to the destination queue. Set the
' body of the message to the ADO recordset.
'*******************************************************************
mSend.Label = "Testing Recordset"
mSend.Body = rsSend
mSend.Send qSend
qSend.Close
'*******************************************************************
' Open the destination queue with RECEIVE access, and retrieve the
' message.
'*******************************************************************
Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set mReceive = qReceive.Receive
'*******************************************************************
' Create a new recordset using the body of the retrieved message.
'*******************************************************************
Set rsReceive = mReceive.Body
Debug.Print rsReceive(0) ' Print column 1
Debug.Print rsReceive(1) ' Print column 2
Debug.Print rsReceive(2) ' Print column 3
rsReceive.MoveNext
Debug.Print rsReceive(0) ' Print column 1
Debug.Print rsReceive(1) ' Print column 2
Debug.Print rsReceive(2) ' Print column 3
End Sub