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
 SQL Server Administration (2005)
 Forcing a database into single user mode?

Author  Topic 

bryan42
Starting Member

28 Posts

Posted - 2011-06-28 : 15:48:45
What's the best way to force a busy database into single user mode?

I'm running this in a job and it fails each time:
ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-28 : 15:57:48
Is the job step running from that database? Change it to master and see if it works.
Go to Top of Page

bryan42
Starting Member

28 Posts

Posted - 2011-06-28 : 16:08:20
It's already running with master specified in the step.

I've seen some posts discuss killing all the current connections. Trying that, I'm finding new connections are made while I'm killing the current ones, so connections almost always remain when I try to change to single user mode. It's a busy database. There's got to be a way to do this, though.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-28 : 16:12:28
Here's what I do on a busy system:

ALTER DATABASE [dbname] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

KILL the users (loop through)

ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

If any of your users qualify as RESTRICTED_USER, then you should disable their accounts after the RESTRICTED_USER command and before the KILL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-06-28 : 16:24:31
You said it's failing. What's the error message?

Do you have enough permission to alter database?
Go to Top of Page
   

- Advertisement -