在备份数据库的时候,分离数据库失败,不能操作数据库
USE master go IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[P_KillConnections]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1 ) DROP PROCEDURE [dbo].[P_KillConnections] GO CREATE PROC P_KillConnections @dbname VARCHAR(200) AS DECLARE @sql NVARCHAR(500) DECLARE @spid NVARCHAR(20) DECLARE #tb CURSOR FOR SELECT spid=CAST(spid AS VARCHAR(20)) FROM master..sysprocesses WHERE dbid=DB_ID(@dbname) OPEN #tb FETCH NEXT FROM #tb INTO @spid WHILE @@fetch_status = 0 BEGIN EXEC('kill '+@spid) FETCH NEXT FROM #tb INTO @spid END CLOSE #tb DEALLOCATE #tb go --修改一下 EXEC P_KillConnections '数据库名'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。