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请问: exec('kill') +@spid 这行为什么错了? 

解决方案 »

  1.   

    exec('kill') +@spid 
    这能加??
      

  2.   

    谢谢各位高手的指点!
    我想实现还原数据库:程序如下:(存储过程如上)
    protected void Button2_Click(object sender, EventArgs e) 

    string path = "e:\\MAZ数据库备份\\" +  "abc.bak"; string connectionStringTest = "server=localhost ;database=abc;uid=sa;pwd=sa"; 
    SqlConnection connection = new SqlConnection(connectionStringTest); 
    string backupstr = "restore database Menu from disk='" + path + "';"; 
    try 

    string sql = "exec killspid  abc" 
    SqlCommand cmd = new SqlCommand(sql, connection); 
    connection.Open(); 
    cmd.ExecuteNonQuery(); 
    cmd = new SqlCommand(backupstr, connection); 
    cmd.ExecuteNonQuery(); 
    MessageBox.Show("恢复成功!"); 
    connection.Close(); 

    catch (Exception ex) 

    string stringError = ex.ToString(); 
    MessageBox.Show("恢复失败!"); 
    connection.Close(); 
    } } 结果显示:恢复失败!请教哪里错了?
      

  3.   

    调试显示:cmd.ExecuteNonQuery();  出错。
      

  4.   

    存储过程已改为:exec ('kill' + @spid )
    楼上“没有赋值”是什么意思?