Error: the database could not be exclusively locked to perform the operation[解决办法]

今天Attach一个数据库,想对数据库重命名,结果报如下错误:

Error: the database could not be exclusively locked to perform the operation.(Microsoft Sql Server,Error 5030)

 

根据http://social.msdn.microsoft.com/Forums/sqlserver/en-US/73311770-92a1-4ff8-b29b-0462f6053a17/error-the-database-could-not-be-exclusively-locked-to-perform-the-operation-in-sql-server-2008-?forum=transactsql上面的介绍,发现如下solution可行:

USE [master];
GO
ALTER DATABASE old_db_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
EXEC sp_renamedb N'old_db_name', N'new_db_name';
GO 
ALTER DATABASE [new_db_name'] SET MULTI_USER 


 

你可能感兴趣的:(error,5030)