Rename SQL 2005 Database - Error: The database could not be exclusively locked to perform the operation.

During database restore, I tried to rename existing database in SQL Server 2005 by simply trying following command:
ALTER DATABASE mydatabase MODIFY NAME = mydatabase_OLD

But it didn't work and gave following error:
"The database could not be exclusively locked to perform the operation."

In order to fix, I had to set it to single user for a while, change the name and then set it back to multi-user.

I had to execute following commands to make it work:

ALTER DATABASE mydatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE mydatabase MODIFY NAME = mydatabase_OLD
GO
ALTER DATABASE mydatabase_OLD SET MULTI_USER
GO

Comments

Post a Comment

Feel free to give constructive feedback or let me know if it was helpful.

Popular posts from this blog

Unable to delete Shared Services Provider in SharePoint (MOSS)

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Cannot add a SimpleContent column to a table containing element columns or nested relations