Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to force a database into single user mode so a script can be run to rename databases? I find I have to Restart the instance of SQL (to force off any connections from a web app, etc.) and then I can run this script:

USE master
sp_dboption MDS, "single user", true
sp_dboption StagingMDS, "single user", true
sp_renamedb MDS, LastMonthMDS
sp_renamedb StagingMDS, MDS
sp_dboption LastMonthMDS, "single user", false
sp_dboption MDS, "single user", false

After this script runs, I can restart IIS for my web app and it can connect to the new production database.

All the above works well and we've been doing this for years but now we've upgraded to SQL 2008 and the SQL2008 instance also hosts other databases that support other web apps.

So, rather than using a Restart of the whole SQL instance to enable subsequent single-user mode on 2 databases, is there a less intrusive way of accomplishing this? Thanks.

share|improve this question

This should kill any open connections to the database:

alter database mds set single_user with rollback immediate

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.