Run SQL command if my connection fails? (SQL Server)

Here is the sequence of events that my hypothetical program does ...

  • Open a connection to the server.
  • Run the UPDATE command.
  • Go away and do something that can take a considerable amount of time.
  • Run another UPDATE, which changes the change in step 2.
  • Close the connection.

But oh no! During step 3, the machine running this program literally exploded. Other machines requesting the same database will now think that the exploded machine is still working and is doing something.

What I would like to do is like opening a connection, but before any changes are made, tell the server that this connection must be closed for some reason in order to run some SQL. That way, I can be sure that if something goes wrong, the closure update will happen.

(To warn the answer, I am not looking for locking tables and records or transactions. I am not claiming resources here).

Thanks a lot, billpg.

+3
source share
3 answers

I'm not sure if something is built in there, so I think you will have to do some custom-made things ...

This is absolutely hypothetical and straight from the head, but:

  • Take the SPID of the connection that you open and save it in a temporary table order, with the text reversal update.
  • ( SSIS - ) temp , SPID .
  • , revert
  • , SPID temp, , .

!

+1

. , , . , , , , .

, SQL, , , , . SQL Server 2005 +.

, , , , , . , , , .

+1

, ... , . , - - .

The approach I must take is to start the process on another machine, which periodically pings the first one to check if everything is online, and then takes action if it becomes unavailable.

0
source

All Articles