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)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.