[Database] Common problems in restoring SQL Server database

When dealing with database restoration, the error message (the database is in use) often appears.

Insert picture description here
As the name suggests, because there are still people or applications that are still connecting to use this database, SQL Server refuses to let anyone restore this database. The solution is very simple. Use sp_who2 to find out the connected SPID (Server Process ID), and then use the kill command to kill this SPID. Then you can continue to restore the database.

Insert picture description here
If there are only one or two SPIDs to kill, you can slowly use the kill command to process, but if there are dozens or hundreds of SPIDs to kill, you must use a more scientific method to solve them. You can use this T-SQL to kill all SPIDs at once.

Insert picture description here
However, if you encounter some very aggressive and sticky link settings, it will be a bit troublesome. When the SPID of this link is killed, a new link is automatically generated immediately and quickly. There is no way to kill it completely. At this time, you can come up with a killer trick, which is to find out this aggressive login, and then disable this login. It can't connect to the database. Wait until the database is restored, then enable (enable) this login.

Insert picture description here

Guess you like

Origin blog.csdn.net/wlcs_6305/article/details/114837847