Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 进程id';x';不是活动进程ID_Sql_Tsql_Sql Server 2008 R2 - Fatal编程技术网

Sql 进程id';x';不是活动进程ID

Sql 进程id';x';不是活动进程ID,sql,tsql,sql-server-2008-r2,Sql,Tsql,Sql Server 2008 R2,我需要将trans日志文件恢复到数据库DBrestore中,该数据库每1小时处于待机模式。因此,我创建了一个作业,它首先终止所有进程,然后将日志文件恢复到数据库中,但有时作业会失败,并给出错误信息:进程id“71”不是活动进程id,进程id每次失败都会更改。 我正在使用此查询终止进程 declare @sql as varchar(20), @spid as int select @spid = min(spid) from master..sysprocesses where dbid

我需要将trans日志文件恢复到数据库DBrestore中,该数据库每1小时处于待机模式。因此,我创建了一个作业,它首先终止所有进程,然后将日志文件恢复到数据库中,但有时作业会失败,并给出错误信息:进程id“71”不是活动进程id,进程id每次失败都会更改。 我正在使用此查询终止进程

declare @sql as varchar(20), @spid as int
select @spid = min(spid)  from master..sysprocesses  
 where dbid = db_id('DBrestore') 
 and spid != @@spid    

while (@spid is not null)
begin
print 'Killing process ' + cast(@spid as varchar) + ' ...'
set @sql = 'kill ' + cast(@spid as varchar)
exec (@sql)

select 
    @spid = min(spid)  
from 
    master..sysprocesses  
where 
    dbid = db_id('DBrestore') 
    and spid != @@spid
end 
我需要在此查询中进行哪些更改,以确保它只接受处于活动状态的进程id


提前感谢

在下面链接中提供的文档中,它提到“活动”流程是通过状态捕获的。如果将其添加到where条件,则应将查询限制为活动进程

declare @sql as varchar(20), @spid as int
select @spid = min(spid)  from master..sysprocesses  
 where dbid = db_id('DBrestore') 
 and spid != @@spid    

while (@spid is not null)
begin
print 'Killing process ' + cast(@spid as varchar) + ' ...'
set @sql = 'kill ' + cast(@spid as varchar)
exec (@sql)

select 
    @spid = min(spid)  
from 
    master..sysprocesses  
where 
    dbid = db_id('DBrestore') 
    and spid != @@spid
    and status = 'running'
end 

@maSTAShuFu,因为你的评论毫无用处。。答案是非常正确和有效的。虽然它缺乏解释,但它成功地指向了一个正确的资源或文档,这本身就足够了。@EricHartman感谢您的回复。我将在查询中使用状态重试