views:

76

answers:

4
        finally
        {
            // Commit the transaction.
            sqlTran.Commit();

            reader.Close();
            reader.Dispose();

            conn.Close();
            conn.Dispose();            
        }

i would like to give the user an option of opps! roll it back so its commited can it be rolled back?

+4  A: 

commited transaction can never be rolled back, while you want your transaction to be persistent after a commit.

Are you looking for savepoints?

Tobias P.
+3  A: 

Well if it committed, it is committed. No rolling back. If you want to be dumb-user-proof, set up a timer and commit only after a delay, giving the user the option to rollback for a while.

Mau
There could be some issues with this solution. For example, what happens if your systems lose power before the timer fires? The user will assume the transaction was committed, when in fact it will be rolled back.
Darvis Lombardo
+2  A: 

simply no. you cannot :)

The Commit method is equivalent to the Transact-SQL COMMIT TRANSACTION statement. You cannot roll back a transaction once it has been committed, because all modifications have become a permanent part of the database.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit.aspx

anishmarokey
A: 

If you put your 'oops!' case at the appropriate point you should be able to do what you need.

Also, take a look at nested transactions, maybe that'll fit your scenario even better.

Finally as Tobias points out there are save points.

Unreason