Baran Topal

Baran Topal


May 2024
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


killing existing SQL server connection except the login started by current session

baranbaran

This is a handy one that I found while googling. Credits to the owner of the script.

These are the steps you need to follow:
1) Stop SQL Server instance
2) Start SQL Server instance in Single user mode
3) Run the Restore command
4) Stop SQL Server instance
5) Start SQL Server instance in Multi user mode


Net stop MSSQLSERVER
Net start MSSQLSERVER /m
sqlcmd -S ServerName\instanceName -E -Q "RESTORE DATABASE databasename FROM DISK='C:\Backup\databasename.bak'"
Net stop MSSQLSERVER
Net start MSSQLSERVER