Monday, October 4, 2010

Unable to rename database in SQL Server Management Studio 2008

Today I wanted to rename a SQL Server 2008 database so I would have a rollback if my create from script went bad.

Upon rename SQL Server Management Studio 2008 gave me the error 'The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)'

I executed this in a query window connected to the master database:
sp_who2

Looking at the DBName column in the results for each match of the db I was trying to rename I executed 'kill xxx' where xxx was equal to the SPID of the row.

After doing this for all the rows rename succeeded immediately.

3 comments:

Anonymous said...

hello!This was a really impressive topic!
I come from roma, I was luck to come cross your subject in bing
Also I get a lot in your blog really thanks very much i will come later

Unknown said...

Thanks! exactly what I was looking for.

Spood Udimo said...

Awesome. This was the one post that got me to the bottom of a regularly occurring issue for me. Thanks!