Note that there are some explanatory texts on larger screens.

plurals
  1. POTransaction not rolling back in c#
    primarykey
    data
    text
    <pre><code>private void btnConfigure_Click(object sender, EventArgs e) { try { dbConfigure dc = new dbConfigure(); SqlTransaction tr = conn.BeginTransaction(); cmd.Transaction = tr; if (dc.configuration(cmd, ps.tableNames)) tr.Commit(); else { tr.Rollback(); mesg.show("Transaction is Rolled back"); } } catch (Exception ex) { mesg.show(ex.Message); } } </code></pre> <p>If i get problem anywhere in <code>configuration</code> method then it returns me false and I can see the message <code>Transaction is Rolled Back</code>. But actually transaction is not rolled back completely and some changes in database structure made by this function stay there inspite of rollback which is quite undesired. My Question is <strong>What can be the possibility of malfunctioning of Transaction roll back?</strong> </p> <p>I have nowhere else any transaction in my project except the shared (above) method</p> <p><strong>Little Details</strong></p> <p>I am calling a very lengthy/complex function <code>configuration</code> of my class <code>dbConfigure</code>. It makes some required changes in database strucure. e.g. It</p> <ol> <li>Drops foriegnKeys</li> <li>Drops Primary keys</li> <li><p>Drops auto-increment fields</p> <p>It saves these keys before dropping and recreates in desired order/position</p></li> </ol> <p><code>conn</code> is an <code>SqlConnection</code> which is already opened, I use no connection anywhere other than this</p> <p><code>cmd</code> is <code>conn.CreateCommand()</code> I use no command anywhere other than this</p> <p>I never close the connection in this whole process, however SqlDataReader's are closed in <code>configuration</code> function when they do their job.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload