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)?