Thursday, September 24, 2020

The database could not be exclusively locked to perform the operation. While renaming database

 

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


While renaming database :( 

/*You might have seen "The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)" error when you try to rename SQL server database.  This error normally occurs when your database is in Multi User mode where users are accessing your database or some objects are referring to your database.


 Nothing much to do to resolve the issue. First set the database to single user mode and then try to rename the database and then set it back to Multi user mode./*

 --We will go through step by step.

--First we will see how to set the database to single user mode,

ALTER DATABASE OlddbName 
SET SINGLE_USER WITH ROLLBACK IMMEDIATE


--Now we will try to rename the database

ALTER DATABASE OlddbName MODIFY NAME = NewdbName


--Finally we will set the database to Multiuser mode


ALTER DATABASE NewdbName
SET MULTI_USER WITH ROLLBACK IMMEDIATE

 

--Hope you are able to rename your database without any issues now!!!

 

No comments:

Post a Comment