Take SQL Server Database Offline
Last updated
Was this helpful?
Last updated
Was this helpful?
To start SQL Server Management Studio
Left click Start
All Apps
Microsoft SQL Server Tools
Microsoft SQL Server Management Studio
Or alternatively, as the SQL Server Tools path will be appended to your users %PATH% variable:
Right click Start
Run
Enter ssms in ‘Open’
Object Explorer will likely open automatically, but if it doesn’t do the following:
View
Object Explorer (or, just F8)
Now, we’ll connect to the database engine.
Connect
Database Engine…
Server name: (in our example I’m connecting to a named instance call SQL2017 on my local machine, so the full name of the SQL Server is .\SQL2017)
Authentication (presuming you’re using Active Directory authentication)
Connect
The name of the database we’re going to take offline is called MyDatabase.
Expand server dropdown
Expand Databases dropdown
Right click on database name – MyDatabase
Tasks
Take Offline
If the Status is ‘Ready’, there are no connections in the database.
Check Status
OK
But, if the status is ‘Not Ready’ as shown below.
Click on the ‘Message’ link
As we can see in our example, it’s telling us there is one connection in the database we want to take offline. The message box tells us to close the connections or select the ‘Drop All Active Connections’ box. We can take care of this in one of two ways.
Option #1
Click ‘New Query’
Run EXEC sp_who2 in the query window
F5 (or click Execute button)
Look under the DBName column for any referenced to the database we’re taking offline and note the corresponding number under the SPID column
Next, run kill with the spid on any that are in the database. Here we only have one with a spid = 57.
Type in ‘kill x’ for each spid and highlight it
F5 (or click Execute)
Highlight ‘EXEC sp_who2’
F5 (or click Execute)
Verify process has been killed
Go back to the Object Explorer.
Right click on database name, MyDatabase
Tasks
Take Offline
In the Take Database Offline window, do the following:
Check Status
OK
One thing to note here. We could have just checked ‘Drop All Active Connections’ to force connections out. But the SQL Server is keeping us from taking the database offline for a reason, which is to protect us from ourselves. It’s just safer to see what connection(s) are in the database first. If you were accidentally attempting to take an active production database offline you would probably be able to catch the mistake before you made it.
Look in the Object Explorer to be sure the database shows (Offline).
If not, do the following:
Right click ‘Databases’
Refresh