Database in Use When Renaming a Database in SQL Server
Why I am getting this error when renaming a database in SQL Server?
If you are trying to rename a database that is in use, you will get an error message like this: "The database could not be exclusively locked to perform the operation."
Before renaming a database, you must stop all client sessions using this database. Otherwise, you will get an error as shown in this tutorial example:
1. Launch one instance of SQL Server Management Studio and run:
USE FyiCenterComData GO
2. Keep the first instance running and launch another instance of SQL Server Management Studio:
ALTER DATABASE FyiCenterComData MODIFY NAME = FyiCenterData GO Msg 5030, Level 16, State 2, Server LOCALHOST\SQLEXPRESS The database could not be exclusively locked to perform the operation.
Obviously, the first instance is blocking the "ALTER DATABASE" statement.
2016-11-20, 644👍, 0💬
How Can Windows Applications Connect to Oracle Servers in Oracle? A Windows application can connect ...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
How To Install PHP on Windows in MySQL? The best way to download and install PHP on Windows systems ...
How to set database to be READ_ONLY in SQL Server? Databases in SQL Server have two update options: ...
How To Change the Password for Your Own User Account in MySQL? If you want to change the password of...