Created
October 24, 2017 15:34
-
-
Save donaldgray/3c903525eedb527f907fdf8c74397374 to your computer and use it in GitHub Desktop.
Script to grab single user mode and set back to multi user. Useful in event of DB in single user but something like polling service grabs connection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Check user with access | |
SELECT | |
p.loginame | |
FROM | |
sys.databases d | |
inner join sys.sysprocesses p ON (d.database_id = p.[dbid]) | |
WHERE | |
d.name = 'database_name' | |
-- Try to grab database 1000 times | |
Use [database_name] | |
GO 1000 | |
-- Set database to multi user mode | |
ALTER DATABASE [database_name] SET MULTI_USER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment