0

我有以下代码。程序刚刚退出,调用没有返回值。有任何想法吗?

AS400System system = new AS400System();
system.Define(ConfigurationManager.AppSettings["AS400Server"]);
system.UserID = ConfigurationManager.AppSettings["AS400User"];
system.Password = ConfigurationManager.AppSettings["AS400Password"];
system.IPAddress = "10.98.1.21";
system.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd);



if(system.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 1) {
    Program program = new Program();
    program.LibraryName = "P2PTST";
    program.ProgramName = "AUI0XFR";
    program.system = system;
    program.system.Signon();

    string paramStatus = "A";
    Int64 paramStockItem = Int64.Parse(t.EtagNumber);
    Guid paramGuid = Guid.NewGuid();
    string paramReturn;

    StringConverter stringConverter = new StringConverter();
    ProgramParameters parameters = new ProgramParameters();
    parameters.Append("ApiIGuid", cwbrcParameterTypeEnum.cwbrcInout, 38);
    parameters.Append("StockItemNumber", cwbrcParameterTypeEnum.cwbrcInout, 20);
    parameters.Append("ItemStatus", cwbrcParameterTypeEnum.cwbrcInout, 1);
    parameters.Append("ReturnCode", cwbrcParameterTypeEnum.cwbrcInout, 7);

    parameters["ApiIGuid"].Value = stringConverter.ToBytes(paramGuid.ToString().PadRight(38, ' '));
    parameters["StockItemNumber"].Value = stringConverter.ToBytes(paramStockItem.ToString().PadRight(20, ' '));
    parameters["ItemStatus"].Value = stringConverter.ToBytes(paramStatus.ToString());

    try{
        program.Call(parameters);
        paramReturn = stringConverter.FromBytes(parameters["ReturnCode"].Value);

        system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll);
    }
    catch (Exception ex)
    {
       Console.WriteLine(ex);
    }
}

4

1 回答 1

0

我们刚刚经历了这个并且遇到了同样的问题,因此决定创建并使用存储过程在 .NET 中完成此任务。因为我们担心让 400 端分发代码来创建存储过程,所以它很快就继续在 PC 端创建过程,然后是我们的远程命令,所以不需要对400边。

我的环境是 Win7 x64,运行 VS2012 C#、CAX V7.1,并导入 IBM.Data.DB2.iSeries 和 System.Data;

我需要 System.Data 作为参数。这对于取回数据至关重要!

我发送 400 两个参数,filesetID 和一个名称。我得到一个数字和一个 uuid。(但他们都是角色!)

它看起来像这样:

    public void RemoteCmd(ref PicMeta pm)
    {
    iDB2Connection cn;
        try
        {
            using (cn = new iDB2Connection("DataSource=<servername/IP>; UserID="<user>"; Password="<pass>";"))
            {
                cn.Open();
                using (iDB2Command cm = cn.CreateCommand())
                {
                    //Place a try/catch here, so it will create the procedure the first time, or any time it has been removed from the 400.  If already set, it will fail, and you'll go directly to the remote command.  
                    try
                    {
                         //Here we create a procedure and execute or continue.
                         cm.CommandText = "CREATE PROCEDURE LIBRARY.SP_PICGETID(INOUT FSET CHAR (1 ), INOUT UNIT CHAR (6 ), INOUT NEXTID CHAR (3 ), INOUT UUID CHAR (36 ))  LANGUAGE RPGLE NOT DETERMINISTIC NO SQL CALLED ON NULL INPUT EXTERNAL NAME LIBRARY.PICGETID PARAMETER STYLE GENERAL";
                         cm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.Out.WriteLine(ex.Message);
                    }

                    //Continue - create and call the command     
                    //ParameterDirection needs "using System.Data;"
                    cm.CommandTimeout = 0;
                    cm.CommandType = System.Data.CommandType.StoredProcedure;
                    cm.CommandText = "LIBRARY.SP_PICGETID";

                    iDB2Parameter p = new iDB2Parameter();
                    p.ParameterName = "FSET";
                    p.Direction = ParameterDirection.Input;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 1;
                    p.iDB2Value = pm.fileset;
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "UNIT";
                    p.Direction = ParameterDirection.Input;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 6;
                    p.iDB2Value = pm.unit;
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "NEXTID";
                    p.Direction = ParameterDirection.InputOutput;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 3;
                    p.iDB2Value = "";
                    cm.Parameters.Add(p);

                    p = new iDB2Parameter();
                    p.ParameterName = "GUUID";
                    p.Direction = ParameterDirection.InputOutput;
                    p.iDB2DbType = iDB2DbType.iDB2Char;
                    p.Size = 36;
                    p.iDB2Value = "";
                    cm.Parameters.Add(p);

                    cm.ExecuteNonQuery();

                    iDB2ParameterCollection pc = cm.Parameters;

                    //We get our Out parameters here 
                    pm.nextid = pc["NEXTID"].Value.ToString();
                    pm.uuid = pc["GUUID"].Value.ToString();
                }
                cn.Close();
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
        }
        return;
    }

希望这可以帮助!

于 2013-12-17T23:28:48.743 回答