如何使用.net为DB2的sql语句定义终止字符

Yac*_*ack 5 .net c# sql db2

我想执行以下操作

 public void ExecuteNonQuery(string script) {
        try {
            int returnCode;

            var builder = new DB2ConnectionStringBuilder {
                                                             UserID = Context.Parameters["USERID"],
                                                             Password =Context.Parameters["PASSWORD"],
                                                             Database =  Context.Parameters["DATABASE"],
                CurrentSchema =  Context.Parameters["CURRENTSCHEMA"]
            };

            using (var connection = new DB2Connection(builder.ConnectionString)) {

                using (var command = new DB2Command(script, connection)
                    ) {
                    command.CommandType = CommandType.Text;

                    connection.Open();

                    returnCode = command.ExecuteNonQuery();
                    File.WriteAllText(Context.Parameters["LOGFILE"], "Return Code -1 Successful : " + returnCode);
                }
            }
        }
        catch (Exception ex) {
            Trace.WriteLine(ex.StackTrace);
            throw ex;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我正在调用一个脚本,该脚本有多个语句以;;并且在文件末尾包含@符号.在db2命令行上,我可以使用db2 -td @ -f.我想知道如何将@符号定义为语句终止符,以便我可以从csharp执行脚本.这是示例sql文件:

DROP PROCEDURE fred@

CREATE PROCEDURE fred ( IN name, IN id )
specific fred
language sql
b1: begin
      update thetable
      set  thename = name
      where table_id = id;
end: b1
@

grant execute on procedure inst.fred to user dbuser@
Run Code Online (Sandbox Code Playgroud)

小智 0

我不确定我们如何定义分隔符。但是,您可以尝试将整个文本拆分为 C# 中的单独语句,然后一个接一个地执行语句。这对你有用吗?