luni, 21 august 2017

How to disconnect all connections on sql server database |kill all connections |disconnect all users

http://bit.do/dGfCD Tabbles secret sale page.
use master ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE --do you stuff here ALTER DATABASE YourDatabase SET MULTI_USER This video is about killing or disconnect all connections to a database. The easiest way is bringing the database to single user mode and set it back to multiuser mode. This will disconnect all connections form all the users other than current one who is logged to the database. One important aspect here is, do not close the screen once you set the database to single user mode. Because when a database is in single user mode it will allow only a single connection to the database. If you allow dropping your connection and if any other connects to the database you will not be able to connect the database again. So you may have to Stop the SQL server and start again to connect the database. It is also possible to do this using SQL management studio. Right click on the database, go to properties, go to options and move to restrict access option. There you can select the single user mode or multiple user mode. Now The question is why do you need to do this. I mean when, do you want to kill all connections. It is mainly, when you want to have exclusive access to the database. For example a database is not allowing you to restore a backup on this because you cannot grant the exclusive access, then you can bring the database to single user mode; killing all connections; perform your activates and after that set it to the multi user mode. This way you can maintain the exclusive access while you are completing the work.