Re: Unable to call stored procedure with OUT argument
Posted by: Francisco Alberto Tirado Zavala
Date: January 03, 2014 12:37PM

Hello Jose.

Here is a brief explanation why you are getting the exception.
When you call a stored procedure from the server with an output parameter you must define a variable that will store the value to return, for example having the following procedure in the database:
CREATE PROCEDURE test(IN id int, OUT otherId int)
SET otherId=2;

You must call the procedure as follow:
set @x=0;
call test(1, @x);
select @x;

Basis on that, since you are calling the store procedure with a MySqlCommand type of text, you will need to declare first the variable that you will use to store the return value, but instead of do that, I will suggest you to change your code a little bit and execute the MySqlCommand as stored procedure.

Please test with the following code and let us know if you still have the issue:
using(MySqlConnection conn = DBCon.Connect()) {
conn.Open();
MySqlCommand cmd = new MySqlCommand("AsientoSencillo", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("_deudora", deudora);
cmd.Parameters.AddWithValue("_acreedora", acreedora);
cmd.Parameters.AddWithValue("_cantidad", cantidad);
cmd.Parameters.AddWithValue("_comentario", comentario);
cmd.Parameters.AddWithValue("_fecha", fecha);
MySqlParameter p = cmd.CreateParameter();
p.ParameterName = "_nuevo_asiento";
p.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
}

Please note that the parameters name that I used in the code are the same that you use in your stored procedure definition, if the name is different you will get an exception because the names doesn't match.

Thanks for your time.

*** My opinions do not necessarily reflect the opinions of my employeer ***
MySql Windows Experience Team

Options: ReplyQuote


Subject
Written By
Posted
Re: Unable to call stored procedure with OUT argument
January 03, 2014 12:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.