Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Transaction Failure

Author  Topic 

med
Starting Member

2 Posts

Posted - 2007-09-07 : 10:18:09
What would happen if i created a transaction as follows in SQL SERVER 2005:

begin transaction test1
set lock_timeout 0
select * from table1 with (UPDLOCK)


and before commiting it the sql server crashed?

Upon restart Would the transaction be rolled back and the lock released, or would the transaction still be open and hanging?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-07 : 10:31:29
the transaction will be rolled back and the lock will be released.

and your lock_timeout being set to 0 means that the select will return an error immediatly
if it can't acquire an UPDLOCK

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

med
Starting Member

2 Posts

Posted - 2007-09-07 : 10:36:43
Thanks,

If the select fails will the transaction close itself?

Will SQL Server eventually clear out open transactions?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-07 : 10:45:01
you should handle commiting transaction yourself.
use try ... catch blocks for error handling.

if the error has high enough severity to prevent further code execution the transaction will be closed.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -