title: Correct way to close database connection in event of exception
body: <p>Does the following code leave the connection open if there is an exception?</p>
  
  <p>I am using a Microsoft SQL compact edition database.</p>
  
  <pre><code>try
  {
      SqlCeConnection conn = new SqlCeConnection(ConnectionString);
  
      conn.Open();
  
      using (SqlCeCommand cmd =
          new SqlCeCommand("SELECT stuff FROM SomeTable", conn))
      {
        // do some stuff
      }
  
      conn.Close();
  }
  catch (Exception ex)
  {
      ExceptionManager.HandleException(ex);
  }
  </code></pre>
  
  <p>Surely a  better way would be to declare a connection object before the try, establish a connection inside the try block and close it in a finally block?</p>
  
  <pre><code> SqlCeConnection conn = null;
   try
   {
      conn = new SqlCeConnection(ConnectionString);
  
      conn.Open();
  
      using (SqlCeCommand cmd =
          new SqlCeCommand("SELECT stuff FROM SomeTable", conn))
      {
        // do some stuff
      }
  }
  catch (Exception ex)
  {
      ExceptionManager.HandleException(ex);
  }
  finally
  {
      if( conn != null )  conn.Close();
  }
  </code></pre>