日期:2014-05-18  浏览次数:20953 次

asp.net 还原数据库,结束sql数据库进程的时候提示游标不存在
还原数据库时,如果不结束进程,会提示占用,下面这个代码是网上流行的结束进程的存储过程

create proc 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


但调用的时候会提示错误:
对象名 'sysprocesses' 无效。
名为 'getspid' 的游标不存在。
名为 'getspid' 的游标不存在。
名为 'getspid' 的游标不存在。
名为 'getspid' 的游标不存在。

请问怎么处理,有没有更好的其他办法?

------解决方案--------------------
如果还不行,我就无语了。