mssql数据库,无法用语句实现“强制还原”功能
2008-12-03 17:31
225 查看
今天在做个小软件发现无法用语句实现MSSQL的“强制还原”功能,总是提示数据库正在使用中,(因为这个库打开过,它很长一段时间才会清除连接。虽然把1433端口封了),试了二个多小时无法解决。后来找到了这个老外写的存储过程解决了问题
Create Proc Sp_KillAllProcessInDB
@DbName VarChar(100)
as
if db_id(@DbName) = Null
begin
Print 'DataBase dose not Exist'
end
else
Begin
Declare @spId Varchar(30)
DECLARE TmpCursor CURSOR FOR
Select 'Kill ' + convert(Varchar, spid) as spId
from master..SysProcesses
where db_Name(dbID) = @DbName
and spId <> @@SpId
and dbID <> 0
OPEN TmpCursor
FETCH NEXT FROM TmpCursor
INTO @spId
WHILE @@FETCH_STATUS = 0
BEGIN
Exec (@spId)
FETCH NEXT FROM TmpCursor
INTO @spId
END
CLOSE TmpCursor
DEALLOCATE TmpCursor
end
GO
--To Execute
Exec dbo.Sp_KillAllProcessInDB 'DBname'
Create Proc Sp_KillAllProcessInDB
@DbName VarChar(100)
as
if db_id(@DbName) = Null
begin
Print 'DataBase dose not Exist'
end
else
Begin
Declare @spId Varchar(30)
DECLARE TmpCursor CURSOR FOR
Select 'Kill ' + convert(Varchar, spid) as spId
from master..SysProcesses
where db_Name(dbID) = @DbName
and spId <> @@SpId
and dbID <> 0
OPEN TmpCursor
FETCH NEXT FROM TmpCursor
INTO @spId
WHILE @@FETCH_STATUS = 0
BEGIN
Exec (@spId)
FETCH NEXT FROM TmpCursor
INTO @spId
END
CLOSE TmpCursor
DEALLOCATE TmpCursor
end
GO
--To Execute
Exec dbo.Sp_KillAllProcessInDB 'DBname'
相关文章推荐
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- T-SQL语句实现数据库备份与还原功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- 利用T-SQL语句,实现数据库的备份与还原的功能
- [MSSQL]SQL Server 2008 通过配置数据库邮件实现发送邮件功能
- 强制还原数据库的时候提示无法获得 独占访问权的解决办法
- 实现数据库的备份与还原的功能
- T-SQL语句实现数据库备份与还原
- [MSSQL]SQL Server 2008 通过配置数据库邮件实现发送邮件功能
- 通过T-SQL语句实现数据库备份与还原的代码
- T-SQL语句实现数据库备份与还原
- (精)如何利用T_SQL实现数据库备份与还原处理之一--(如何利用sql语句,得到数据库文件目录)
- c# winform 实现对postgresql数据库的自动备份还原功能
- mysql update语句 无法实现数据库更改操作
- (精)如何利用T_SQL实现数据库备份与还原处理之一--(如何利用sql语句,正确备份数据库)