title: Why does SQL Transaction does not Rollback after connection is lost - C#?
body: <p>I'm using MariaDB 10.3.21 and I'm wondering why the Rollback is not done from the SQL-Server after the connection is lost.</p>
  
  <p>I'm updating several Tables with the code below. To check if also a rollback from the server side is done after connection lost, I set a breakpoint to the objTransaction.Commit() command and after hitting it, I interrupted the network connection.</p>
  
  <p>Unfortunately the update of the fields are taken over without a commit command. I assumed if a connection is lost the server will do an implicit rollback.</p>
  
  <p>Any Ideas? Many Thanks!</p>
  
  <pre><code>    public void ExecuteSQL(List&lt;string&gt; pQueryList)
      {
          using (MySqlConnection objConnection = new MySqlConnection(ConnectionString))
          {
              try
              {
                  objConnection.Open();
  
                  MySqlCommand objCommand = objConnection.CreateCommand();
                  MySqlTransaction objTransaction;
  
                  // Start Transaction
                  objTransaction = objConnection.BeginTransaction();
  
                  // Must assign both transaction object and connection
                  // to Command object for a pending local transaction
                  objCommand.Connection = objConnection;
                  objCommand.Transaction = objTransaction;
  
                  try
                  {
                      // Set autocommit = off the this session
                      //objCommand.CommandText = "SET autocommit = 0";
                      objCommand.ExecuteNonQuery();
  
                      foreach (string query in pQueryList)
                      {
                          // Execute the SQL Queries
                          objCommand.CommandText = query;
  
                          if (objCommand.ExecuteNonQuery() &lt;= 0)
                          {
                              throw (new Exception("Fehler bei ExecuteNonQuery. Anzahl der betroffenen Zeilen fehlerhaft."));
                          }
                      }
  
                      // Commit Transaction
                      objTransaction.Commit();
                  }
                  catch (Exception)
                  {
                      for (int i = 0; i &lt; 3; i++)
                      {
                          // Rollback 3x versuchen (falls Netzwerkverbindung abgebrochen ist)
                          try
                          {
                              objTransaction.Rollback();
                              break;
                          }
                          catch (Exception)
                          {
                              Thread.Sleep(100);
                          }
                      }                        
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show("Das speichern in die Datenbank ist fehlgeschlagen!\n\n" + ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
              }
          }
      }
  </code></pre>