title: Best practices of disposing of SqlConnection, SqlTransaction, SqlCommand, SqlDataAdapter objects
body: <p>Are ALL the sqlCommand, sqlTransaction and sqlDataAdapter objects <strong>automatically</strong> disposed on exit from the "using" block (in which sqlConnection disposed) or all these objects to be disposed <strong>should be in separated</strong> nested "using" blocks, otherwise these objects will not be disposed when sqlConnection object disposed? What are the best practices? </p>
  
  <pre class="lang-cs prettyprint-override"><code>public static void ExecuteDataset(string connectionString, string storedProcedure, SqlParameter[] sqlParameters = null)
  {
      SqlTransaction sqlTransaction = null;
  
      using (SqlConnection sqlConnection = new SqlConnection(connectionString))
      {
          try
          {
              sqlConnection.Open();
  
              SqlCommand sqlCommand = new SqlCommand(commandText, connection);
              command.Parameters.Add("@ID", SqlDbType.Int);
  
              sqlCommand.Connection = sqlConnection;
              SqlTransaction = sqlConnection.BeginTransaction();
              sqlCommand.Transaction = sqlTransaction;
              .....................................................
              .....................................................    
  
              SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
  
                  ................................
                  ................................
  
  
              sqlTransaction.Commit();
          }
          catch (Exception)
          {
              sqlTransaction.Rollback();
          }
      }        
  }
  </code></pre>