How to poll if the connection is still alive?
Posted: Fri 24 Nov 2006 09:39
Hello all,
I'm using Psion terminals which are connected to our database via a wireless lan. Sometimes it happens that the wireless signal quality is too low, so the connection gets closed. What I need is a fast way to determine if the connection is still open. At this moment I'm doing it in the following manner:
This function is called each time before I execute a query and if it returns false I try to open the connection again for a number of times. However this function is too slow for my liking. It takes about 300-500 msecs to check and that is way too much.
Is there any faster way to determine if my connection is still open?
Note 1: I tried to use the PgSqlConnection.StateChangeEvent, but it is only triggered after you try to use the connection. If that weren't the case I would have been using this event to track my connection's state.
Note 2: I saw the MySql Library indeed has a Ping() function. Will it be in the PgSql Library too (or is this not possible)?
I'm using Psion terminals which are connected to our database via a wireless lan. Sometimes it happens that the wireless signal quality is too low, so the connection gets closed. What I need is a fast way to determine if the connection is still open. At this moment I'm doing it in the following manner:
Code: Select all
Private Shared Function PgSqlPing() As Boolean
Dim query As String = "select 0"
Dim command As New PgSqlCommand
Try
command.CommandText = query
command.Connection = m_connection
command.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
Finally
command.Dispose()
End Try
End Function
Is there any faster way to determine if my connection is still open?
Note 1: I tried to use the PgSqlConnection.StateChangeEvent, but it is only triggered after you try to use the connection. If that weren't the case I would have been using this event to track my connection's state.
Note 2: I saw the MySql Library indeed has a Ping() function. Will it be in the PgSql Library too (or is this not possible)?