Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:12:55+00:00 2026-06-14T14:12:55+00:00

private void btnConfigure_Click(object sender, EventArgs e) { try { dbConfigure dc = new dbConfigure();

  • 0
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);
    }
}

If i get problem anywhere in configuration method then it returns me false and I can see the message Transaction is Rolled Back. 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 What can be the possibility of malfunctioning of Transaction roll back?

I have nowhere else any transaction in my project except the shared (above) method

Little Details

I am calling a very lengthy/complex function configuration of my class dbConfigure. It makes some required changes in database strucure. e.g. It

  1. Drops foriegnKeys
  2. Drops Primary keys
  3. Drops auto-increment fields

    It saves these keys before dropping and recreates in desired order/position

conn is an SqlConnection which is already opened, I use no connection anywhere other than this

cmd is conn.CreateCommand() I use no command anywhere other than this

I never close the connection in this whole process, however SqlDataReader’s are closed in configuration function when they do their job.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:12:56+00:00Added an answer on June 14, 2026 at 2:12 pm

    Changes to database structure are not transactional, so you cannot rollback creation of a new table, for example

    BS. Most DDL is transactional and can be rolled back. Only changes that involve interactions with non transactional components (like the filesystem, eg. adding a new file to a database) cannot be rolled back. Any DDL that is non transactional will also very explicitly raise an exception if is invoked in an active transaction.

    Adding and modifying tables is very explicitly transactional, and it can easily be ilustrated with an example:

    begin transaction;
    create table foo (a int);
    select * from sys.tables where object_id = object_id('foo');
    rollback;
    select * from sys.tables where object_id = object_id('foo');
    

    Therefore the problem lies in the OP missing code, the parts not posted.

    As a general comment one should use System.Transactions when possible (with consideration that the default constructor is broken). If using SqlConnection.BeginTransaction one still better rely on the IDisposable:

    using (SqlTransaction trn = conn.BeginTransaction())
    {
       ...
       trn.Commit ();
    }
    

    System.Transactions should be favored though as they do not depend on code discipline, any code SqlClient in the transaction scope will automatically enroll.

    And btw have the configuration function raise on error, not return false.

    And on the underlying real problem: how to handle a lenghy, complicated migration that is not possible to be enrolled in one single transaction (eg. it simply could generate too much log). The answer is that the only feasible option is to take a database backup at the beginning of the migration and restore from this backup if the migration fails. The alternative of providing a manual, tested and reliable, compensating action for every migration operation in order to undo the migration is incredibly difficult, errorprone, and ultimately unnecessary since restoring from a backup is so much simpler and provable correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private void button5_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(Data Source=MAZI-PC\\PROJECTACC;Initial Catalog=programDB;Integrated
private void btnMiles_Click(object sender, EventArgs e) { try { int milesless200 = int.Parse(txtMiles.Text); int
private void btnMail_Click(object sender, EventArgs e) { new formCustomerReportMailer().Show(); } Is it ill-advised to
private void button1_Click(object sender, EventArgs e) { using (SqlConnection sqlConn = new SqlConnection(Data Source=TANYA-PC;Initial
private void mnuCustomerAdd_Click(object sender, EventArgs e) { CustomerForm frmCust = new CustomerForm(Add A New
private void button2_Click(object sender, EventArgs e) { ChangeLink cl = new ChangeLink(); // Show
private void button2_Click(object sender, EventArgs e) { cl = new ChangeLink(); cl.StartPosition = FormStartPosition.CenterParent;
private void btnGo_Click(object sender, EventArgs e) { Array IDlist = txtUserID.Text.Split(new char[] { });
private void btnDump_Click(object sender, EventArgs e) { using (StreamWriter sw = new StreamWriter(E:\\TestFile.txt)) {
private void buttonSaveXML_Click(object sender, EventArgs e) { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.