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
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:
This changes would give following code:
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
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.