The database could not be exclusively locked to perform the operation.
When performing an operation in a database (such as changing the database name or changing the Collation setting …), you may experience such an error.
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:
ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
USE MyDB GO sp_renamedb N'MyDB', N'MyDB_Old'
ALTER DATABASE MyDB_Old SET MULTI_USER