0

I use the following method to calculate data:

  public static int PrepareData(int year, int month, int calcYear)
        {
            using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["testable"].ToString()))
            {
                int res = 0;
                StringBuilder cmdTxt = new StringBuilder();
                cmdTxt.Append(" hk_calc_data ");
                using (var myIfxCmd = new IfxCommand(cmdTxt.ToString(), con))
                {
                    myIfxCmd.CommandType = CommandType.StoredProcedure;

                    myIfxCmd.Parameters.Add("p_year", IfxType.Integer);
                    myIfxCmd.Parameters.Add("p_month", IfxType.Integer);
                    myIfxCmd.Parameters.Add("p_calc_year", IfxType.Integer);

                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    myIfxCmd.Parameters[0].Value = year;
                    myIfxCmd.Parameters[1].Value = month;
                    myIfxCmd.Parameters[2].Value = calcYear;
                    myIfxCmd.CommandTimeout = 1000;
                    res = myIfxCmd.ExecuteNonQuery();
                }
                con.Close();
                con.Dispose();
                return res;
            }
        }

It takes no time and always returns -1! Although when I ran it in SQL editor with the same parameters, it takes about 4 minutes to complete and return 1 as result!

Alberto Solano
  • 7,972
  • 3
  • 38
  • 61
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Have you tried removing the `CommandTimeout`? – Dirk Feb 25 '14 at 10:17
  • yeah the same problem . it takes no time at all !!! and return -1 !! – Anyname Donotcare Feb 25 '14 at 10:18
  • Well, I don't know much about Informix but I would remove the extra spaces around the name of the stored procedure. And keep in mind that the return value of a stored procedure is not the same as the return value of the `ExecuteNonQuery()`. The [documentation](http://pic.dhe.ibm.com/infocenter/idshelp/v117/index.jsp?topic=%2Fcom.ibm.net_cc.doc%2Fcom.ibm.swg.im.dbclient.adonet.ref.doc%2Fdoc%2FDB2CommandClassExecuteNonQueryMethod.htm) I found says "For all other types of statements [other than INSERT, UPDATE, DELETE statements], the return value is -1". – Dirk Feb 25 '14 at 10:26

1 Answers1

1

Maybe try clearing the params first, and also adding value with the Add.

                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                myIfxCmd.Parameters.Clear();
                myIfxCmd.Parameters.Add("p_year", IfxType.Integer, year);
                myIfxCmd.Parameters.Add("p_month", IfxType.Integer, month);
                myIfxCmd.Parameters.Add("p_calc_year", IfxType.Integer, calcYear);
smoore4
  • 4,520
  • 3
  • 36
  • 55
  • I do it then i get the following exception !! `ERROR [HY090] [Informix .NET provider]Invalid string or buffer length.at res = myIfxCmd.ExecuteNonQuery();` – Anyname Donotcare Feb 25 '14 at 16:13