When deleting a database today, an error is reported. The error message is: this database is in single-user mode and is still in connection and cannot be deleted (this is also true even when is stopped and then started)
Baidu then found a solution, backed up here:
Use [Master] Go/****** object: storedprocedure [DBO]. [killspid] script Date: 03/28/2011 11:01:32 *****/set ansi_nulls ongoset quoted_identifier ongo -- creates a stored procedure and disconnects all users. Create proc [DBO]. [killspid] (@ dbname varchar (20) as begin declare @ SQL nvarchar (500) declare @ spid int set @ SQL = 'descare getspid cursor for select spid from sysprocesses where dbid = db_id (''' + @ dbname + ''') 'exec (@ SQL) open getspid fetch next from getspid into @ spid while @ fetch_status <>-1 begin exec ('kill' + @ spid) fetch next from getspid into @ spid end close getspid deallocate getspid end go
Create a stored procedure in the master to kill all connections and then call
Use master exec killspid 'problematic database name'
Delete the file and then click OK.