快捷搜索:

c#动态创建存储过程中,提示'go' 附近有语法错误

1public int CreateDB_KillProc_proc()

2{

3int result = 0;

4string SqlStr = "";

5//组合Sql语句

6SqlStr += @"USE [RadarDataBase]

7GO

8SET ANSI_NULLS ON

9GO

10SET QUOTED_IDENTIFIER ON

11GO

12create proc [dbo].[P_KillConnections]

13@dbname varchar(200)

14as

15declare @sql nvarchar(500)

16declare @spid nvarchar(20)

17declare #tb cursor for

18select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)

19open #tb

20fetch next from #tb into @spid

21while @@fetch_status=0

22begin

23exec('kill '+@spid)

24fetch next from #tb into @spid

25end close #tb deallocate #tb ";

26

27//履行Sql语句

28try

29{

30result = DbHelperSQL.ExecuteSql(SqlStr);

31}

32catch (Exception e)

33{

34ErrStr = e.Message;

35return -2;

36}

37return result;

38}

您可能还会对下面的文章感兴趣: