0

I'm using MySQL's AUTO_INCREMENT field and InnoDB to support transactions. I noticed when I rollback the transaction, the AUTO_INCREMENT field is not rollbacked? But when I don't call RollBack the id doesn't change.

try
{

//My Code
}
catch (MySqlException ex)
{
    //deadlock exception in mysql   
    if (ex.Number == 1213)
    {
        //I don't use RollBack and the id dosen't change
        MessageBox.Show("Try again", "Warning");
    }
    else
    {
        msqlTr.Rollback();
        txtError.Text = "Erreur : " + ex.Message;
        Log.LogError.setError(ex);
        MessageBox.Show("Erreur : " + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
catch (Exception ex)
{
    msqlTr.Rollback();
    txtError.Text = "Erreur : " + ex.Message;
    Log.LogError.setError(ex);
    MessageBox.Show("Erreur : " + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

If this code correct, I mean that when I don't call rollback?

Cœur
  • 37,241
  • 25
  • 195
  • 267
hassan
  • 1

1 Answers1

0

The Identity Increment happens outside of the transaction. That is working as expected.

MySQL AUTO_INCREMENT does not ROLLBACK

Community
  • 1
  • 1
Wyatt Earp
  • 1,783
  • 13
  • 23