On this page
Determines whether connection to Oracle server is valid.
Syntax
|
|---|
'Declaration
Public Function Ping() As Boolean |
Return Value
true, if the connection is valid; otherwise, false.
Example
This code sample shows how to check for server availability before issuing a query.
|
|---|
public void ExecuteSafely(OracleConnection connection)
{
OracleCommand command = new OracleCommand("INSERT INTO Dept(DeptNo, DName) Values('50', 'DEVELOPMENT')");
command.Connection = connection;
try
{
if (connection.Ping())
{
command.ExecuteNonQuery();
Console.WriteLine("Successfully executed");
}
else
{
connection.Close();
Console.WriteLine("Unable to ping the server");
}
}
catch
{
connection.Close();
Console.WriteLine("Error during query execution");
}
} |
|
|---|
Public Sub ExecuteSafely(ByVal connection As OracleConnection)
Dim command As New OracleCommand("INSERT INTO Dept(DeptNo, DName) Values('50', 'DEVELOPMENT')")
command.Connection = connection
Try
If (connection.Ping()) Then
command.ExecuteNonQuery()
Console.WriteLine("Successfully executed")
Else
connection.Close()
Console.WriteLine("Unable to ping the server")
End If
Catch
connection.Close()
Console.WriteLine("Error during query execution")
End Try
End Sub |
See Also