dbTalk Databases Forums  

A solution for existing connection was forcibly closed

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss A solution for existing connection was forcibly closed in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
antleite2001@gmail.com
 
Posts: n/a

Default 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.