title: Winforms Applications best way to handle loss of database connection without the application crashing
body: <p>I hope this isn t too general a question.</p>
  
  <p>I have quite a few winforms applications which connect to the same sql database.</p>
  
  <p>On one of my servers the CPU is getting to 100% (which is an issue in itself which needs to be investigated).
  So i'm getting a - 'The underlying Provider Failed to open'</p>
  
  <p>So my issue is there are a lot of repository requests within the applications and i don t really want to put try catches around all of them - although i have done the following in the main method of one of them:</p>
  
  <pre><code>connDb1  == false;
  while (connDb1 == false)
                  {
                      try
                      {
                         //code in here with various connection to db though repositories...
                          connDb1 = true;
                      }
                      catch (Exception)
                      {
                          connDb1 = false;
                          _keepItDry.AddTolistBox(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + ": Error connection to DB may have failed - try again... ", _listBoxLog);
                          Thread.Sleep(60000);//wait 1 minute and try again
                      } 
                  }
  </code></pre>
  
  <p>Has anyone got a good solution for how to check if the db connection has been lost and retry without the application crashing.</p>
  
  <p>Or is it a case of going through the applications and anywhere which connects error handle there.</p>
  
  <p>I hope this makes sense.</p>
  
  <p>Many thanks</p>