Determines whether connection to PostgreSQL server is valid.
'Declaration
Public Function Ping() As Boolean
Return Value
true, if the connection is valid; otherwise, false.
This code sample shows how to check for server availability before issuing a query.
public void ExecuteSafely(MySqlConnection myConnection)
{
MySqlCommand myCommand = new MySqlCommand("INSERT INTO Test.Dept(DeptNo, DName) Values('50', 'DEVELOPMENT')");
myCommand.Connection = myConnection;
try
{
if (myConnection.Ping())
{
myCommand.ExecuteNonQuery();
Console.WriteLine("Successfully executed");
}
else
{
myConnection.Close();
Console.WriteLine("Unable to ping the server");
}
}
catch
{
myConnection.Close();
Console.WriteLine("Error during query execution");
}
}
Public Sub ExecuteSafely(ByVal myConnection As MySqlConnection)
Dim myCommand As New MySqlCommand("INSERT INTO Test.Dept(DeptNo, DName) Values('50', 'DEVELOPMENT')")
myCommand.Connection = myConnection
Try
If (myConnection.Ping()) Then
myCommand.ExecuteNonQuery()
Console.WriteLine("Successfully executed")
Else
myConnection.Close()
Console.WriteLine("Unable to ping the server")
End If
Catch
myConnection.Close()
Console.WriteLine("Error during query")
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2