Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 591867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:40:48+00:00 2026-05-13T15:40:48+00:00

I need to call a stored procedure multiple times, I’m using informix. I would

  • 0

I need to call a stored procedure multiple times, I’m using informix. I would like to know if calling a procedure multiple times with the same connection is the same generating the string with the multiple calls to the stored procedure and executing that as a query.

this is an example of the code:

IfxCommand cmd = new IfxCommand("storeData", myconn);
cmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < lbim; i++)
{

  cmd.Parameters.Add("id", IBM.Data.Informix.IfxType.VarChar, 255).Value = info.id;
  cmd.Parameters.Add("descripcionDescuentoImpuesto", IBM.Data.Informix.IfxType.VarChar, 255).Value = info.data[i].value;
  try
  {
     IfxDataReader myreader = cmd.ExecuteReader();
     if (myreader.Read())
     {
        Boolean aux = (Boolean)myreader[0];
        myreturn = aux;
     }
     myreader.Close();
  }
  catch (IfxException ex)
  {
  }
  cmd.Parameters.Clear();
}

The problem is that each stored procedure returns true or false.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:40:48+00:00Added an answer on May 13, 2026 at 3:40 pm

    For performance reasons the best approach is to prepare command before loop. Inside the loop you can set parameter values and execute the reader.
    I would also improve the code with 2 things:

    • using factories; this way you can easily switch between OdbcDriver and IfxDriver or something else in the future;
    • error handling: you should close reader in finally section or use “usings” clause which guarantees freeing resources in case of exception; I prefere usings because in more complex scenarios finally section becomes very complicated.

    This changes would give following code:

    DbProviderFactory dbfactory;
    dbfactory = DbProviderFactories.GetFactory("IBM.Data.Informix");
    using (myconn = dbfactory.CreateConnection())
    {
        myconn.ConnectionString = " ... ";
        myconn.Open();
        DbCommand cmd = dbfactory.CreateCommand();
        cmd.Connection = myconn;
        cmd.CommandText = "storeData";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Clear();
    
        DbParameter parameter = dbfactory.CreateParameter();
        parameter.ParameterName = "id";
        parameter.DbType = DbType.String;
        parameter.Size = 255; // probably not necessary
        cmd.Parameters.Add(parameter);
    
        parameter = dbfactory.CreateParameter();
        parameter.ParameterName = "descripcionDescuentoImpuesto";
        parameter.DbType = DbType.String;
        parameter.Size = 255;
        cmd.Parameters.Add(parameter);
    
        cmd.Prepare();
        for (int i = 0; i < lbim; i++)
        {
            cmd.Parameters[0].Value = info.id;
            cmd.Parameters[1].Value = info.data[i].value;
            using (DbDataReader myreader = cmd.ExecuteReader()) {
                if (myreader.Read())
                {
                    Boolean aux = (Boolean)myreader[0];
                    myreturn = aux;
                }
            }
        }
    }
    

    Code is now much longer but I think that advantages are prevailing. Even better approach is to use Spring.NET (I’m just learning it) – half the size of the code, driver independend (similarly to factories approach), automatic disposal of resources in case of exception.
    Also I would use rather

    myreturn = (bool)cmd.ExecuteScalar();

    instead of data reader.
    Next thing is that I’m using command type text rather and “execute procedure storeData(?,?)”. This is because of Informix bug in some scenarios which I’ve got long time ago. Possible that this is already fixed – so probably it is no longer necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call a stored procedure using JPA and found this article: http://www.oracle.com/technology/pub/articles/vasiliev-jpql.html
I am using Entity Framework 5 and need to make multiple stored procedure calls
I need to call a stored procedure several times. How can I put this
I'm using Oracle DB. And I need to call stored procedure sequentially for 1000
I need to call a stored procedure and pass arguments in from Powershell. I
What is the best way to make a call to a stored procedure using
I need to call a stored procedure in Oracle from an orchestration. I am
I'm working on a legacy system, and I need to call a stored procedure
I need to use a cursor to call a stored procedure that has 2
I have an existing stored procedure in SQL Server that I need to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.