Revolutionary approach to check whether connection to database will work for next command

by Miha Markič 21. January 2008 14:23

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.

Tags:

.net

Comments (5) -

Mladen
Mladen
1/21/2008 4:42:29 PM #

noone in that thread ever heard of
select * from information_schema.tables where table_name = 'yourTableName'
?

Reply

Miha Markic
Miha Markic
1/21/2008 4:57:52 PM #

Sure, even I suggested this approach (in general terms) as way to go. Note that this isn't just about SQL server, but rather database in general.

Reply

Mladen
Mladen
1/21/2008 5:16:29 PM #

true.
afaik all db's have some kind of metadata you can chek for table existance.
but it's a very funny and entertaining thread Smile)

Reply

ML
ML
1/21/2008 5:26:24 PM #

Must be one of them brain doners. I hope he/she is replying from home, and not currently employed in IT (or anywhere else for that matter).

Reply

Jens Samson
Jens Samson
1/21/2008 5:50:43 PM #

Idiots are like death and taxes, a sad part of life.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Miha Markic

About me
Righthand
 
Microsoft MVP
 
Developer Express' DXSquad
INETA Country Leader for Slovenia
INETA Country Leader for Slovenia

Slovene Developer Users Group Lead
Friends of Red-Gate
LLBLGenPro Partner

Miha currently works as a free lance consultant and software developer specialized in .net area.
He graduated in Computer and information science at the University of Ljubljana, Slovenia. He has accumulated experience in various programming languages such as Java, Visual Basic 3-6 (MCP), Visual C++, Delphi, C# and VB.Net through years.
He has experience in practically all (technical) stages of project development, including planning, framework development, user interface, business processes, as well as testing and documenting. He has worked on big and small projects in Slovenia and abroad (e.g. participated in completing level 3 IS for the Nucor steel plant, Hertford, USA).
Currently he enjoys programming in .net environment using C#. Since 2000 he has been active in Developer Express' DX Squad and has been ECDL trainer and tester. He also gives lectures on conferences and other events in Slovenia.

Month List

Tag cloud

Most comments

Paulius Paulius
1 comments
us United States
Meh Meh
1 comments
us United States
bart dm bart dm
1 comments
nl Netherlands

RecentComments

Comment RSS