16
Answers

rollback of last updated queries in sql server

Ravi Shekhar

Ravi Shekhar

11y
1.4k
1


Hello seniors,

I have two  buttons. On the click of first button i update some rows in sql server table.
but my operation will complete after click on second button.

suppose after clicking on first button my server will close enexpectedly or someone close server directly. 
Is there any option availiable in sql server to rollback my last update query if the server is down enexpectedly.


Please give suggestion.
Answers (16)
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
yes, I am referring the same. You just try and rest upto you.

Regards,
Iftikar
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y


My server machine is connected with 5 PC through lan. My apps is running not on the server machine .Apps is running on the other PC.   
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
your server is down, not your system (WHERE YOU ARE RUNNING YOUR APPLICATION). So I am not understanding why you will not able to get exception. For testing purpose just give some dummy connection string and check
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y



When My server PC is down (due to any reason) means Main sql server is down. In this case how can i manage any query in catch??

0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
your server is down, not your system. So I am not understanding why you will not able to get exception. For testing purpose just give some dummy connection string and check
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y


I can understand your words, But sir when my server system is close then how can i run any query in catch ????
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
in that case you will SqlConnection exception. Better when you click on second button, use try-catch and handle this exception. In that you can write your logic to clean it.

Regards,
Iftikar
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y


But sir i can manage in any other exception. But when my server is shutdown (due to any reason). How can i run update command????


0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
Then you can implement same thing whenever you got any error from sql server while clicking on second button click. Just clear your temp and set it to null.

Regards,
Iftikar
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y



If i click add statustemp would P. on save statustemp would picklistno.

If i click add statustemp would P. on close or cancel statustemp would again NULL.

Means i reserve temprorely my stock on add and release on close or cancel.

And i reserve permanently after save.

Now clear???

0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
ok, what will happen for the below scenario
if I add the item today and don't click on save button and come back tomorrow and click on save button.

Regards,
Iftikar

0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y

Attachment untitled.rar



Please find attached image for reference.
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y




I am making a picklist . when i click on add button my stock is reserve for me . on the click of add i update statustemp column as P. Now to complete to making picklist click on save button on the save button i again update statustemp column as picklist number.

but suppose after click on add my server close unexpectedly. now my reserve stock would not show in other picklist generation .

    • Statustemp column value -   

    • by default NULL

    • after Add -

    • P

  • after Save - 
    • Put picklistno


0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
what exactly you trying to do it with two button? Can you explain it?

Regards,
Iftikar
0
Ravi Shekhar

Ravi Shekhar

NA 5.4k 969.9k 11y



I want to rollback my last updated data which was not complete...
my my operation would complete after clicking on second button.

0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
Hi,
        It will be not possible to rollback except restore the database.

Regards,
Iftikar