An exception occurred while the SQL Server database was offline, as follows:
===================================
Setting offline for Database "SMS" failed. (MICROSOFT.SQLSERVER.SMO)
------------------------------for help information, click: Http://go.microsoft.com/fwlink? prodname=microsoft+sql+server&prodver=10.50.2500.0+ ((kj_pcu_main). 110617-0038+) &EvtSrc= microsoft.sqlserver.management.smo.exceptiontemplates.failedoperationexceptiontext&evtid= Setting up offline +database &linkid=20476
------------------------------Program Location:
In Microsoft.SqlServer.Management.Smo.Database.SetOfflineImpl (Boolean offline) in Microsoft.SqlServer.Management.Smo.Database.SetOffline () in Microsoft.SqlServer.Management.SqlManagerUI.DatabaseOffline.DatabaseOfflineAction.DoAction ( Progressitemcollection actions, Int32 index) in Microsoft.SqlServer.Management.SqlStudio.Controls.ProgressItemCollection.DoWorkOnThread ()
===================================
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------Program Location:
In Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery (String SqlCommand, executiontypes Executiontype) in Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery (stringcollection Sqlcommands, Executiontypes Executiontype) in Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery ( StringCollection queries) in Microsoft.SqlServer.Management.Smo.Database.SetOfflineImpl (Boolean offline)
===================================
ALTER database failed because the lock could not be placed on database ' SMS '. Please try again later. The ALTER DATABASE statement failed. (. Net SqlClient Data Provider)
------------------------------for help information, click: Http://go.microsoft.com/fwlink? prodname=microsoft+sql+server&prodver=10.50.2550&evtsrc=mssqlserver&evtid=5061&linkid=20476
------------------------------Server name: (local) Error number: 5061 severity: 16 Status: 1 line number: 1
------------------------------Program Location:
In MICROSOFT.SQLSERVER.MANAGEMENT.COMMON.CONNECTIONMANAGER.EXECUTETSQL (executetsqlaction action, Object Execobject, DataSet FillDataSet, Boolean catchexception) in Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery (String SqlCommand, executiontypes Executiontype)
Workaround:
Use the following command to get the session of the current DB, then kill the corresponding SPID and then execute the ALTER DATABASE statement.
EXEC Sp_who2;
KILL <SPID>;
An exception occurred while the
SQL Server database was offline: ALTER database failed because the lock could not be placed on database ' SMS '. Please try again later. The ALTER DATABASE statement failed. (. Net SqlClient Data Provider)