以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 Dot NET,C#,ASP,VB 』 (http://bbs.xml.org.cn/list.asp?boardid=43) ---- c#动态创建存储过程中,提示go 附近有语法错误解决方案 (http://bbs.xml.org.cn/dispbbs.asp?boardid=43&rootid=&id=85331) |
-- 作者:卷积内核 -- 发布时间:6/14/2010 2:31:00 PM -- c#动态创建存储过程中,提示go 附近有语法错误解决方案 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 } 32 catch (Exception e) 33 { 34 ErrStr = e.Message; 35 return -2; 36 } 37 return result; 38 }
但执行过程中出现错误
以下是我在查询分析器中能正常使用的脚本代码。 1 USE [RadarDataBase] 所以将带有GO的语句分成多条sql语句,执行多条SQL语句,实现数据库事务,代码如下:
1 public int CreateDB_KillProc_proc() |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
46.875ms |