1 public int CreateDB_KillProc_proc()
2 {
3 int result = 0;
4 string SqlStr = "";
5 //組合Sql語句
6 SqlStr += @"USE [RadarDataBase]
7 GO
8 SET ANSI_NULLS ON
9 GO
10 SET QUOTED_IDENTIFIER ON
11 GO
12 create proc [dbo].[P_KillConnections]
13 @dbname varchar(200)
14 as
15 declare @sql nvarchar(500)
16 declare @spid nvarchar(20)
17 declare #tb cursor for
18 select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
19 open #tb
20 fetch next from #tb into @spid
21 while @@fetch_status=0
22 begin
23 exec(kill +@spid)
24 fetch next from #tb into @spid
25 end close #tb deallocate #tb ";
26
27 //執行Sql語句
28 try
29 {
30 result = DbHelperSQL.ExecuteSql(SqlStr);
31 }