Currently, my database is in Single User mode. When I try to expand me database, I get an error:
The database \'my_db\' is not accessible.(ObjectExplo
Adding to Jespers answer, to be even more effective:
SET DEADLOCK_PRIORITY 10;-- Be the top dog.
SET DEADLOCK_PRIORITY HIGH uses DEADLOCK_PRIORITY of 5.
What is happening is that the other processes get a crack at the database and, if your process has a lower DEADLOCK_PRIORITY, then it loses the race.
This obviates finding and killing the other spid (which might need to be done several times).
It is possible that you would need to run ALTER DATABASE more than once, (but Jesper does that). Modified code:
USE [master]
SET DEADLOCK_PRIORITY HIGH
exec sp_dboption '[StuckDB]', 'single user', 'FALSE';
ALTER DATABASE [StuckDB] SET MULTI_USER WITH NO_WAIT
ALTER DATABASE [StuckDB] SET MULTI_USER WITH ROLLBACK IMMEDIATE