Powered by Blogger.

Saturday, February 15, 2014

The database could not be exclusively locked to perform the operation rename database in sql server 2008



In this post we will discuss how we can resolve the error The database could not be exclusively locked to perform the operation which comes while renaming an existing database in sql server 2008.

Also you can check out my previous posts on:

- How to disable right click by using jQuery in asp.net?

- Some Optimization Tips in sql server.

- Method Overloading in C#.Net

Recently I got the error while trying to rename an existing database name by following this articles. The error was: The database could not be exclusively locked to perform the operation.

The error comes because other users using the same database. So we should make the database so that it can be used by yourself only. And after rename you can change back so that other users can use this.

So to rename the db I need to follow the below 3 steps sequentially and the error gone.

ALTER DATABASE TestDB
SET SINGLE_USER WITH ROLLBACK IMMEDIATE

ALTER DATABASE TestDB
Modify Name = TestDBNew ;

ALTER DATABASE TestDBNew
SET MULTI_USER WITH ROLLBACK IMMEDIATE

Now you should be able to successfully rename the db as well as you should not get any error.



0 comments

Post a Comment