Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql server 2008 how do i disconnect everyone from my db?

I need to rename the database, but I cannot since other processes is using it. I don't care about the process, and I need to kill it.

How do I remove all connections from the db?

like image 301
Alex Gordon Avatar asked Nov 19 '10 23:11

Alex Gordon


People also ask

How do I disconnect all users from a SQL database?

Right-click the server in Object Explorer and select 'Activity Monitor'. When this opens, expand the Processes group. Now use the drop-down to filter the results by database name. Kill off the server connections by selecting the right-click 'Kill Process' option.

How do I close all db connections?

Right-click on a database in SSMS and choose delete. In the dialog, check the checkbox for "Close existing connections." Click the Script button at the top of the dialog.

How do I detach all databases in SQL Server?

Step 1. : Connect to SQL Server instance and open SSMS. Step 2: Go to Tools tab in SSMS and select Option. Step 3 : Select Query Result option and then go to SQL Server and Result to Grid. Step 4 : Enable check box Retain CR/LF on copy or save and click OK.


3 Answers

As per my comment once in single_user mode you need to do the rename from the same connection. Don't try and rename it through Object Explorer as that will try and open up a new connection. The following works this end...

ALTER DATABASE AdventureWorks SET single_user WITH ROLLBACK IMMEDIATE

ALTER DATABASE AdventureWorks MODIFY NAME = NewAdventureWorks

ALTER DATABASE NewAdventureWorks SET multi_user 
like image 54
Martin Smith Avatar answered Oct 01 '22 23:10

Martin Smith


Like this: Kill All Active Connections To A Database

ALTER DATABASE oldNameSET SINGLE_USER WITH ROLLBACK IMMEDIATE

EXEC sp_renamedb 'oldName', 'newName'

ALTER DATABASE newName SET MULTI_USER  --new name of course
like image 26
SQLMenace Avatar answered Oct 01 '22 23:10

SQLMenace


Run sp_who, then kill [pid] for everyone in your database.

like image 36
Stu Avatar answered Oct 02 '22 01:10

Stu