Disconnect all users in the database, - Disconnect all user connections in the specified library (in the Master database)
Use mastergo
IF EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [p_killspid]') And ObjectProperty (id, n'isprocedure ') = 1) Drop Procedure [dbo]. [p_killspid] Go
create proc p_killspid @ dbname sysname - name of the database to be disconnected as declare @s nvarchar (1000) declare tb cursor local forselect s = 'kill' cast (spid as varchar) from master..sysprocesses where dbid = db_id ( @dbname)
Open TB fetch next from tb @Swhile @@ fetch_status = 0begin exec (@s) fetch next from tb @sendclose TBDEAllocate TBGO
- Call the exec p_killspid 'aa' and then use sp_attach_db to stand up to the server