Click to See Complete Forum and Search --> : Sending a RecordSet over the wire


spuppett
November 3rd, 2004, 08:40 AM
Hey all. I'm looking to send a record set from a server to a client. I thought I had it set up, but its not working. I was wonder if you all could look at it and tell me whats wrong?

I get the initial connection, and when I ask for the record set, it get that request to, and it does the send data just fine, but on the client side, I don't get in to the client_dataArrived method.

Thanks in advance.


'this is the server
Option Explicit
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection

Private Sub Form_Load()
listen.LocalPort = 1478
listen.listen
conn.ConnectionString = Adodc1.ConnectionString
conn.Open
rs.CursorType = adOpenDynamic
rs.Source = "SELECT * FROM hours"

Set rs.ActiveConnection = conn
rs.Open

End Sub

Private Sub Form_Unload(Cancel As Integer)
listen.Close
recieve.Close
Debug.Print "SOCKETS CLOSED"
End Sub

Private Sub listen_Close()
listen.Close
Debug.Print "Listen Close"
End Sub

Private Sub listen_ConnectionRequest(ByVal requestID As Long)
recieve.Accept requestID
Debug.Print requestID & ": requestID"
recieve.SendData Now
End Sub

Private Sub recieve_Close()
recieve.Close
Debug.Print "RECIEVE CLOSED"
End Sub

Private Sub recieve_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
recieve.GetData dat, vbString
If dat = "RECORD" Then
recieve.SendData rs
End If
End Sub




'this is the client
Option Explicit
Dim database As String
Dim rsHours As New ADODB.Recordset
Dim con As New ADODB.Connection

Private Sub cmdGet_Click()
socket.SendData "RECORD"
End Sub

Private Sub cmdOK_Click()
socket.Close
Unload Me
End Sub

Private Sub Form_Load()
setUpSocket
setUpFlexGrid
End Sub

Private Sub Form_Unload(Cancel As Integer)
socket.Close
End Sub

Private Sub setUpFlexGrid()

End Sub

Private Sub setUpSocket()
socket.RemotePort = 1478
socket.RemoteHost = "xxx.xx.xx.xxx"
socket.Connect
End Sub

Private Sub socket_Close()
socket.Close
Debug.Print "SOCKET CLOSED"
End Sub

Private Sub socket_DataArrival(ByVal bytesTotal As Long)
Dim rs As New ADODB.Recordset
Dim rightNow As Date
socket.GetData rightNow
End Sub

jp140768
November 3rd, 2004, 09:50 AM
You have made a connection to your socket "Listen" (in the server), yet the server then starts using (socket??) receive - why do you switch sockets, especially when you have established a connection to a different socket.

In your client, you have the following two line of code:
Dim rightNow As Date
socket.GetData rightNow

Your server on the other hand has:
Private Sub listen_ConnectionRequest(ByVal requestID As Long)
recieve.Accept requestID
Debug.Print requestID & ": requestID"
recieve.SendData Now
End Sub

followed by:
Private Sub recieve_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
recieve.GetData dat, vbString
If dat = "RECORD" Then
recieve.SendData rs
End If
End Sub

I could only see one occurance of you receiving data in the client, and you are always expecting a date.

I think your data arrival is not being fired because you have switched sockets - I don't think you are connected to the second socket.

You may be better to publish this in the VB forum, as at the moment it relates to VB code instead of DB issues.

HTH

spuppett
November 3rd, 2004, 10:01 AM
I just made another simple client/server, that when the client connects, the server sends a record set. Right now the RS is small, 3 records(just to test). It connects, but doesn't send the data.

However, when I send just a string, it works like a champ.

What I am wondering is, has anyone/can anyone show me how send an ADO recordset through a socket?

I've read that using RDO with Jet isn't the best idea, and I've never used RDO before.

Thanks.

jp140768
November 3rd, 2004, 12:31 PM
I'm not sure that you will be able to, the socket seems to just send a string of data eg I use it to transfer files from one computer to another, files are opened in binary and the bits are sent across. Have you looked at sending it as a stream instead of a recordset?

What is your application, is there a reason why you want to send a recordset, as opposed to say a record?

spuppett
November 3rd, 2004, 01:49 PM
The app is a time card, of sorts. All that I really want is a the names of employees to come across to populate a combo box. I ended up making a sting on the server side and sending that and the parsing it on the client side. But that just seems like a lot of work for the client. I would like to pass an entire recordset and shove it into a local one, it seems much simpler.

You mentiond something about passing a record. How would I do this? or a stream?

Thank you.

jp140768
November 4th, 2004, 11:04 AM
The recordset has a property called GETSTRING which allows you to return the results of your recordset as a string, and put in delimiters which may make life easier for you??

I couldn't find any help on the Stream object within my MDAC SDK, so can't help you there, you may find something on the MSDN website though, or in the VB forum.

Why are you using winsock? Do you have to cross a firewall? / the internet?

spuppett
November 4th, 2004, 11:06 AM
Yeah, itll go over the internet. I work for a temp agency, and the idea is that one of our temps is working elsewhere. When they get to work, they can punch in there, but it gets sent to us here.