Network Management
Taking SQL DB offline takes a long time in SQL Management Studio
Taking a SQL Server database offline using the following query in SQL Management Studio takes a long time: ALTER DATABASE <dbname> SET OFFLINE WITH ROLLBACK IMMEDIATE. The following error is displayed: ALTER DATABASE failed because a lock could not be placed on database 'dbname' Try again later.
First published date
Last published date
Overview
Taking a SQL Server database offline using the following query in SQL Management Studio takes a long time:
-- Scripts are not supported under any SolarWinds support program or service. -- Scripts are provided AS IS without warranty of any kind. SolarWinds further -- disclaims all warranties including, without limitation, any implied warranties -- of merchantability or of fitness for a particular purpose. The risk arising -- out of the use or performance of the scripts and documentation stays with you. -- In no event shall SolarWinds or anyone else involved in the creation, -- production, or delivery of the scripts be liable for any damages whatsoever -- (including, without limitation, damages for loss of business profits, business -- interruption, loss of business information, or other pecuniary loss) arising -- out of the use of or inability to use the scripts or documentation. ALTER DATABASE <dbname> SET OFFLINE WITH ROLLBACK IMMEDIATE
The following error is displayed:
ALTER DATABASE failed because a lock could not be placed on database 'dbname' Try again later.
Product section
Cause
MSSQL is unable to close open connections.
Resolution
- Run the following:
-- Scripts are not supported under any SolarWinds support program or service. -- Scripts are provided AS IS without warranty of any kind. SolarWinds further -- disclaims all warranties including, without limitation, any implied warranties -- of merchantability or of fitness for a particular purpose. The risk arising -- out of the use or performance of the scripts and documentation stays with you. -- In no event shall SolarWinds or anyone else involved in the creation, -- production, or delivery of the scripts be liable for any damages whatsoever -- (including, without limitation, damages for loss of business profits, business -- interruption, loss of business information, or other pecuniary loss) arising -- out of the use of or inability to use the scripts or documentation. EXEC sp_who2
- Locate the database in the results, and locate the SPID for that connection.
- Run the following:
-- Scripts are not supported under any SolarWinds support program or service. -- Scripts are provided AS IS without warranty of any kind. SolarWinds further -- disclaims all warranties including, without limitation, any implied warranties -- of merchantability or of fitness for a particular purpose. The risk arising -- out of the use or performance of the scripts and documentation stays with you. -- In no event shall SolarWinds or anyone else involved in the creation, -- production, or delivery of the scripts be liable for any damages whatsoever -- (including, without limitation, damages for loss of business profits, business -- interruption, loss of business information, or other pecuniary loss) arising -- out of the use of or inability to use the scripts or documentation. KILL <SPID>