Is there any way to configure SQL Server 2008 to kill a transaction if it has neither been canceled nor committed for some time? (Say power, network connection or whatever gets cut to the computer having it open.)
Either so it happens automatically after some defined rule-sets or by making and calling a command line application that queries the SQL server for active transactions + time they have been running… and then instructs SQL Server to close those down that are “frozen”.
To quote Gail Shaw from here:
Whichever tech that you’re using to connect (ADO, etc.) will probably have a connection timeout and and execution timeout property that you can change in your calling code. Defaults are usually 30 secs.
You could potentially wrap something like this in a loop that kills each offending spid:
There would probably be many opinions on how to best find which processes are “safe” to kill, and I would certainly be a little worried about automatically doing such a thing based upon an arbitrary timespan. I’m also not sure that any data changes done in the process are guaranteed to be rolled-back.