在使用vbs导入数据库时确实会存在数据库正在读写或者正在使用中的报错提示,其实数据库已经进入单用户模式,无人调用,写一个脚本来杀。

declare @spid int
declare Spid_cursor cursor for
select spid from master.dbo.sysprocesses with (nolock) where loginame = '用户名' and blocked <> 0 order by spid
open Spid_cursor
fetch next from Spid_cursor into @spid
while @@FETCH_STATUS = 0
begin
  --exec('kill '+@spid)  //屏蔽后是查询功能
  print 'Killed Spid=' + cast(@spid as nvarchar(200))
  fetch next from Spid_cursor into @spid
end
close Spid_cursor
deallocate Spid_cursor