ERROR MESAGGE:
The database could not be exclusively locked to perform the operation.
EXPLANATION:
When performing an operation in a database (such as changing the database name or changing the Collation setting …), you may experience such an error.
SOLUTION:
There should not be another user connected to the database to perform such operations. You can also do this with a command block as follows. Note that this will kill other sessions in the database.
Change your database name:
1 2 3 4 5 6 | ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO USE MyDB GO sp_renamedb N'MyDB', N'MyDB_Old' GO ALTER DATABASE MyDB_Old SET MULTI_USER GO |