doing the alter database [dbname] set single_user with rollback immediate is great, but only if your connection is using the database.
if you are looping thru them all, i can see where some other process could grab the single use connection.
I've seen examples where they set to single user, then rename the database as teh next statement...(ie DBName_Restoring that way other process don't find the database any more.
Lowell