Possibly save 1 hour of your time: You want to rename a database that is shared with other developer and you receive this error.
</pre> DECLARE @DbName nvarchar(50) SET @DbName = N'replace_your_database_name' DECLARE @EXECSQL varchar(max) SET @EXECSQL = '' SELECT @EXECSQL = @EXECSQL + 'Kill ' + Convert(varchar, SPId) + ';' FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DbName) AND loginame not like '%replace_your_login_name%' EXEC(@EXECSQL) <pre>
The above will remove other people’s connections. Once you close your query window, you can try to rename the database now.
However, I still get message that you cannot kill your own process. Then you need to run the above SELECT statement without checking for your loginname to determine what other sessions you have. Then you can manually run EXEC(‘Kill 78;’). The number here should be your process id.