collegegirly Newbie
Joined: 17 Jan 2004 Posts: 2
|
Posted: Jan 17th, 2004 05:20 PM Post subject: winsock send data problem |
|
|
i am trying to send data from a client form to a server using winsock array on the server side. the problem i am having is i keep getting an error message - "40006 - wrong protocol or connection state for the requested transaction or request". However, the connection between the client and server is active. Is this a common problem? How would i overcome this?
This is the code i am using for the server;
Private Sub ws_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim Strdata As String
ws(Index).GetData Strdata, vbString
If ws(0).State <> 0 Then '& NewConnection(0)) = True Then
Dim UserName As String, Password As String
UserName = Left$(Strdata, 16)
UserName = Trim(UserName)
Password = Right$(Strdata, 16)
Password = Trim(Password)
Dim Flag As Boolean
Flag = False
Dim db As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim query As String
db.ConnectionString = "Data Source=cs;"
db.Open
Dim parameter As String
query = "SELECT user.UserName, user.Password From [user] WHERE (((user.UserName)='" & UserName & "') AND ((user.Password)='" & Password & "'));"
rec.Open query, db
On Error GoTo errorhandler
rec.MoveFirst
If rec.Fields("UserName").Value = UserName And rec.Fields("Password").Value = Password Then
Flag = True
NewConnection(0) = False
End If
db.Close
errorhandler:
Select Case Err.Number
Case 3021:
ws(0).SendData "False"
Exit Sub
End Select
If Flag = True Then
ws(0).SendData "True"
Else
If Flag = False Then
ws(0).SendData "False"
DoEvents
ws(0).Close
End If
End If
Else
Dim test As String
test = Strdata
x = 0
mypos = InStr(1, test, ",", 1)
Do
parser(x) = Left(test, mypos - 1)
test = Mid(test, mypos + 1, Len(test))
mypos = InStr(1, test, ",", 1)
x = x + 1
Loop Until mypos = 0
parser(x) = test
Call DatabaseChoice
' End If
End If
End Sub
This is the code i am using for the client side;
Private Sub Form_Load()
Dim databasechoice As String
ClientPort = 1
ws.Close
ws.LocalPort = ClientPort
ws.Connect lblIP.Caption, 1000 + ClientPort
ws.senddata databasechoice & "," & choice
The trouble is the second client connection that the server receives is not able to send data to the server and this is when we get the error above
Any suggestions would be welcome. |
|