checking for valid connection

  • Thread starter Thread starter Peter Row
  • Start date Start date
P

Peter Row

Hi,

Today we had a thunder storm with lightening/torrental rain the works the
process of which seemed to screw up my 4-port network hub. At the time I was
testing my Windows app which uses a SQL Server database, I changed something
in the UI that required DB access and since by hub had gone it couldn't get
access.

The result was my application hung and I had to use task manager to end it.

So the question is what is the best way to program against this using
VB.NET/ADO.NET?
Have a separate thread that periodically prods the connection to make sure
it's okay, something else?

Regards,
Peter
 
I'm working on my "Getting Connected" chapter in my new book and this
subject came up.
When ADO (wow, I just looked down at your email address... kinda crude isn't
it... well, anyway...) or ADO.NET is using a connection (has it open), it's
kept in the connection pool until you need to perform some operation. Think
of the pooling mechanism as an old switchboard--when your connection is
open, you're "plugged" into a server connection. If the server goes away
(and this did not happen in your case), the network can still be up and the
network interface card can still see the intranet. In this case, it does not
take long for the pooler to notice that the connection is dead. However, if
the NIC is down or the network itself is down (as in your case), the NIC
timeout kicks in. Some cards take longer than others, but it's usually about
a minute before they report problems. This gives systems managers (and
switches) time to route or re-route cables without disturbing the net. Ok,
so the first NIC times out and your application gets an exception. At this
point if you try to close the connection and reopen one, the pooler looks
for another pooled connection and the process is repeated. This can take
quite some time. In ADO.NET 2.0 you can flush the pool if necessary and
actually test the viability of the network. Of course you can do that now as
well, but it's more difficult.
So, bottom line: Exception handlers need to be written to deal with this
sort of (not THAT unusual) occurrence. Just keep in mind that the pooled
connections can get in the way. If you're using a Windows Forms application,
turn it off--it does not help that much anyway.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Hi,

Thanks for the reply, I'm not sure but I think that a wire has been crossed
here.
The network I was using was working fine, my computers network card was
fine. However I use a network hub so that I can plug my laptop and desktop
into a single network socket.

The storm caused the hub to go screwy (I had to power it down and up again
to
reset it) my network card on my machine was working fine still and so was
the server that has SQL Server on, but since the hub went down the
connection between the two was removed.

I tried a few tests like ping'ing first before I end tasked my app I was
testing.
The point being that regardless of if you have exception handling or not
it shouldn't hang. It should either display a message indicating the network
connection has been cut or if it didn't have exception handling, (which it
does by the way) it should crash with a critical error; either way it
shouldn't
just hang.

There must be some way to monitor the connections.

Bye,
Peter
 
The 2.0 Framework has better network monitoring classes, but consider that
the hub is a link in the network. If it's down, there is no Ethernet signal
on the NIC.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top