As we all know, an open connection to database server might drop for a reason or another whenever. And a dead connection is one of the reasons that our command against database server might not succeed – instead we’ll get an exception. I mean, you can’t know in advance if the command will succeed and connection will hold for the lifetime of the execution. It turns out that all who believed the above were wrong.
You can actually predict the success of command execution. Meet ping pong test:
Dim WithEvents Pong as New Ping() Pong.Send(IPAddress) Private Sub Pong_PingCompleted(ByVal sender As Object, ByVal e As _ PingCompletedEventArgs) Handles Pong.PingCompleted If e.Reply.Status <> IPStatus.Success Then GiveUP() ElseIf e.Reply.RoundtripTime > 750 Then TryAgainLater() End If End Sub
The test above is suggested from a guy in ado.net/vb.net newsgroups. He asserts that based on the ping pong success one can predict whether connection to the database server is good, database server is up and running, will execute our command connection and will hold to the end of our command execution.
If one can extrapolate all that knowledge from a simple ping, perhaps there is even more knowledge in i.e. tracert? Is it possible to extrapolate everything (including future and past) from these simple utilities? Who knows.
Read more in “Checking for table existence” thread.
Disclaimer: This post is not serious. It is just reaction to at least funny and at worst dangerous claims (if one takes them as granted) in the newsgroups. The ping pong test just lets you know that server (not database server) is responding to ping command. Nothing else.