WEB开发网
开发学院软件开发C语言 c#动态创建存储过程中,提示go 附近有语法错误解决... 阅读

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

 2010-09-30 22:45:55 来源:WEB开发网   
核心提示:1publicintCreateDB_KillProc_proc()2{3intresult=0;4stringSqlStr="";5//组合Sql语句6SqlStr+=@"USE[RadarDataBase]7GO8SETANSI_NULLSON9GO10SETQUOTED_IDENTI

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 [email protected]) 
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 2 3  下一页

Tags:动态 创建 存储

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接