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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 340k
  • Answers 340k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to look at the JNI functions GetMethodID and… May 14, 2026 at 4:39 am
  • Editorial Team
    Editorial Team added an answer Updating the gem to version 1.3.6 seem solve the problem.… May 14, 2026 at 4:39 am
  • Editorial Team
    Editorial Team added an answer I would do: enum.map {|line| Cab.new(*line.match(/<cab id="(\w+)" updates="(\d+)"/)[1,2]) } or… May 14, 2026 at 4:39 am

Related Questions

I need to create multiple records in sqlserver, each with the same value in
I've asked a few questions on this topic before. Before we're able to implement
I've inherited a project that stores basic HTML formatting (i.e. - < b >
I'm in a situation where I need to make a call to a stored
I have a CRUD-heavy ASP.NET application with all the business logic in Stored Procedures.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.