title: Close SQL connections cleanly when connection dropped
body: <p>Just wondering if there is a way that I can close all SQL connections and commands in the cleanest possible way when a connection is lost in VB.NET (can also be in C#.NET).</p>
  
  <p>What I'm trying to achieve:</p>
  
  <p>Using the System.Net.NetworkInformation.NetworkAvailabilityChanged event, I'm monitoring whether the connection has been lost. If it has been lost, I'm disabling all user input - works great. Network comes back on, UI is enabled. <em>(thumbs up)</em></p>
  
  <p>Now, however, comes my predicament. If an SQL query is executing before the connection drops and then the network is lost, then the query returns a null value as expected, however if that was mid population of datatables/fields, then I get NullReferenceExceptions.</p>
  
  <p>My question is:</p>
  
  <p>Is there anyway to cleanly exit a sub <strong>after</strong> the connection has dropped? I've tried Application.ExitThread, but that doesn't seem to quite cut it. Do I need to put dropped connection handlers within my objects, so that when the connection is dropped, the respective object won't return or try to assign null data?</p>
  
  <p>Any help is greatly appreciated. Not asking for plain code, need explanations if at all possible. Cheers.</p>