Friday, April 23, 2010

Error while renaming database

Error

Unable to rename coltest_Org. (ObjectExplorer)
Rename failed for Database 'coltest'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)

Solution

Check if any other user is using the database or having lock on database object to be rename using following script

DECLARE @Database varchar(128)
Set @Database=''
SELECT DISTINCT SPID
FROM sys.syslockinfo L with(nolock)
INNER JOIN SYS.SYSPROCESSES P with(nolock) ON P.SPID=L.req_spid
WHERE L.rsc_indid=db_id(@Database)
OR P.dbid=db_id(@Database)


Kill the SPID's or wait for it to be completed if not running\suspended.
Then rename database.

No comments:

Post a Comment