Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqlserverdba
Yak Posting Veteran
53 Posts |
Posted - 2009-07-24 : 16:15:16
|
Hi,When I changed database into single user mode. I want to revery back. it's saying someone is accessing. how to fix this issue?Thanks |
|
sqlserverdba
Yak Posting Veteran
53 Posts |
Posted - 2009-07-24 : 16:39:41
|
please help! |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2009-07-24 : 17:56:16
|
[code]declare @db_name sysnamedeclare @spid_to_kill intdeclare @sql nvarchar(4000)-- set database nameset @db_name = 'pubs'-- Find spid of user process in databaseselect top 1 @spid_to_kill = spidfrom sysprocesses a join sysdatabases b on a.dbid = b.dbidwhere b.name = @db_nameset @sql ='use master-- Kill user process connected to databasekill '+convert(nvarchar(10),@spid_to_kill)+'-- Set database to multi useralter database '+quotename(@db_name)+' set multi_user with rollback immediate'print isnull(@sql,'NULL')if @sql is not null begin exec (@sql) end[/code]Results:[code]use master-- Kill user process connected to databasekill 55-- Set database to multi useralter database [pubs] set multi_user with rollback immediate[/code]CODO ERGO SUM |
 |
|
|
|
|