asp.net在线恢复数据库

用于asp.net还原与恢复SqlServer数据库的KillSpid存储过程

CREATE PROCEDURE KillSpid(@dbName varchar(20))
AS
BEGIN
    DECLARE @sql nvarchar(500)
    DECLARE @spid int
    
    SET @sql='DECLARE 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

 

恢复数据库:

  关键字://Alter Database 被恢复的数据库名 Set Offline with Rollback immediate;
            restore database 被恢复的数据库名 from disk = '备份文件路径';
            //Alter Database 被恢复的数据库名 Set OnLine With rollback Immediate;

posted @ 2014-07-26 19:54  shiningrise  阅读(352)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css