0

I am working on a Windows application (WinForms) that requires four different processes to run (stored procedures) that include the ability to commit or rollback the entire process in the instance that any of the four processes raised an error. I'll describe my situation below (and please excuse my SQL ignorance as I am not a DBA):

  • Windows App: Click Process Button

  • Database: Initiate Procedure 1 (and presumably BEGIN TRANSACTION MyProcessTransaction)

  • Windows App: Click Process Button

  • Database: Initiate Procedure 1 (and presumably BEGIN TRANSACTION MyProcessTransaction)

  • Windows App: Receives notification from Procedure 1 that it completed successfully and updates a progress bar.

  • Database: Initiate Procedure 2 (and somehow still encapsulated under MyProcessTransaction)

  • Windows App: Receives notification from Procedure 2 that it completed successfully and updates a progress bar.

  • Database: Initiate Procedure 3 (and somehow still encapsulated under MyProcessTransaction) and raises an error and rolls back the transaction MyProcessTransaction

Is this possible? I tried four query windows and began a transaction in the first, then put try catches in the other windows and attempted to perform work in each to simulate this but when I got to the fourth window and intentionally raised an error, I received the exception that there was no BEGIN TRANSACTION for me to be able to ROLLBACK. Any suggestions?

clockwiseq
  • 4,189
  • 9
  • 38
  • 61

1 Answers1

0

Well, as usual, after doing some digging, I found a solution that works for me. Not that it's the sole solution, but it's efficient and it works:

https://stackoverflow.com/a/13228090/176806

I never put 2 and 2 together to figure out that the TRANSACTION is connection specific, so, I did as suggested and created a transaction via the connection object and passed that transaction from call to call, then in the instance of an error, roll back that transaction. If anyone feels like answering something else, I'm still open to any suggestions.

Community
  • 1
  • 1
clockwiseq
  • 4,189
  • 9
  • 38
  • 61