Braindump of a session where I had to remove a SQL Server database from single-user mode.
execute sp_dboption
1> exec sp_dboption 'testdb01', 'single user', 'FALSE'; 2> go Msg 5064, Level 16, State 1, Server REMIDIAN01, Line 1 Changes to the state or options of database 'testdb01' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it. Msg 5069, Level 16, State 1, Server REMIDIAN01, Line 1 ALTER DATABASE statement failed. sp_dboption command failed.
Now I can use TSQL below to find all the database sesions connected to this database.
TSQL script to retrieve client sessions per database.
select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid where d.name = 'testdb01' go
Kill the particular session(s) with the ;kill’ command.
1> kill 51 2> go 1>
Now I can ‘remove’ the database from Sinlge user mode.
1> exec sp_dboption 'testdb01', 'single user', 'FALSE' 2> go 1>
Found the solution which I had forgotten just in the nick of time as I was dealing with a production implementation. Great Job!!!! Thanks!
Thanks, It worked for us.
Brilliant!!! I found this after spending an hour on same issue and it worked so smooth…
Thanks..this worked
THANKS!!!! :D Solved an urgent issue.
Thank you. This really helped me.
Thank you so much . . .
Brilliant!!! Worked like a charm!!!
I found that I had non-user sessions (spid < 50) and they were blocking me. Restarting the service cleared those and I was able to use this process.
Thank you very very much!
Works fine!
thanks it worked for me