A solution for existing connection was forcibly closed -
08-18-2007
, 05:03 AM
I think this link http://msdn2.microsoft.com/en-us/library/8xx3tyca.aspx
has a solution for this problem, at least with me it is working. What
I did?
Upon a request to a sql server through ethernet/tcpip, i call (for
every request) the function CheckNetworkCondition as described below
Dim a As New NetworkDataSetTableAdapters.QueriesTableAdapter 'Just any
query to test a connection
Dim d As System.Nullable(Of Date)
..
..
..
Public Function CheckNetworkCondition() As Boolean
If My.Computer.Network.IsAvailable AndAlso PingOK() AndAlso
ServerAccessible() Then
Return True
Else'CLEARALLPOOLS IS THE SOLUTION
System.Data.SqlClient.SqlConnection.ClearAllPools( )
Return False
End If
End Function
Private Function ServerAccessible() As Boolean
Try
'GetDateTimeFromServerSP is just any stored procedure
query stored in the server to force a query over the network
a.GetDateTimeFromServerSP(d)
Catch ex As Exception
Return False
End Try
Return True
End Function
Private Function PingOK() As Boolean
Try
If Ping("192.168.7.87") Then 'My sql server address
Return True
Else
Return False
End If
Catch ex As Exception 'In case some exception occurs
Return False
End Try
Return True
End Function
Please note that, if a network fails and recovers without any query in
between, this function will not be called and the connection will be
forcibly closed. So I have a timed procedure which is called once a
second to call CheckNetworkCondition.
Best regards |