views:

16

answers:

1

I'm having trouble executing a stored procedure in ODBC to a DB2 database where a stored procedure has multiple input and output params. If I specify only in input params in the call statement with ? like below, i get "SQL0440 - Routine XXXXXXX in *N not found with specified parameters.". I've changed the output params to be of type 'ReturnValue' or 'Output' with the same result.

Here is my code:

var paramList = new List<OdbcParameter>();

       var param1 = new OdbcParameter("FldId", "SLPMEMST_MESLRY");
       param1.OdbcType = OdbcType.Char;
       param1.Direction = ParameterDirection.Input;
       paramList.Add(param1);

       var param2 = new OdbcParameter("ExtIndex",2346);
       param2.OdbcType = OdbcType.Decimal;
       param2.Direction = ParameterDirection.Input;
       paramList.Add(param2);

       var param3 = new OdbcParameter("LogCmt", "test here");
       param3.Direction = ParameterDirection.Input;
       param3.OdbcType = OdbcType.Char;
       paramList.Add(param3);


        var prmOut1 = new OdbcParameter("PlainText", OdbcType.Char, 32624);
        prmOut1.Direction = ParameterDirection.InputOutput ;

        var prmOut2 = new OdbcParameter("MsgId", OdbcType.Char, 7);
        prmOut2.Direction = ParameterDirection.InputOutput;

        var prmOut3 = new OdbcParameter("MsgText", OdbcType.Char, 80);
        prmOut3.Direction = ParameterDirection.InputOutput;

        var prmOut4 = new OdbcParameter("Errors", OdbcType.Char, 1);
        prmOut4.Direction = ParameterDirection.InputOutput;

        paramList.Add(prmOut1);
        paramList.Add(prmOut2);
        paramList.Add(prmOut3);
        paramList.Add(prmOut4);

        var sproc = "{? =call P_GetEncFld (?, ?, ?)}";
DAL.Common_AS400.RunNonQuery_Parameterized(sproc, paramList,CommonData.ConnectionStringCrypto);


 public static void RunNonQuery_Parameterized(string SQLStatement, IEnumerable<OdbcParameter> parameters, string connectionString)
        {
            OdbcConnection oConn = new OdbcConnection(ConfigurationManager.ConnectionStrings[connectionString].ToString()) { ConnectionTimeout = 300 };
            using (var oCmd = new OdbcCommand())
                {
                    foreach (OdbcParameter param in parameters)
                    {
                        oCmd.Parameters.Add(param);
                    }

                    if (oConn.State != ConnectionState.Open) oConn.Open();
                    oCmd.CommandType = CommandType.Text;
                    oCmd.CommandText = SQLStatement;
                    oCmd.Connection = oConn;
                    oCmd.ExecuteNonQuery();
                }
        }

Ideas?

A: 

That is because your code defined sproc and the sproc itself do not have the same number of paramters. Make sure that your sending and identifying the same number of params in your code. You populate your array paramList but don't declare the call appropriately. Each parameter needs a "?".

"{? =call P_GetEncFld (?, ?, ?, ?, ?, ?, ?)}"
Josaph