Rare behavior of Stored Procedure

0

I have a procedure stored in sql, when I run it in the same sql it runs all Ok:

declare @x as varchar(13)
exec sp_nuevo_codigo 'AGB', ''
print @x
go

But when I run it from C #, vb, Fox Throws this error:

  • in the Profiler:

    declare @p4 varchar(8000)
    set @p4=''
    exec sp_executesql N'exec sp_nuevo_codigo @P1  @P2 OUTPUT ',N'@P1 varchar(3),@P2 varchar(8000) OUTPUT','AGB',@p4 output
    select @p4
    
  • The error:

    Msg 102, Level 15, State 1, Line 23
    Sintaxis incorrecta cerca de '@P2'.
    (1 row(s) affected)
    
asked by Luis Mata 22.06.2017 в 16:36
source

1 answer

1

Be sure to use from c # an sqlCommand with well-defined parameters:

using (SqlCommand cmd = new SqlCommand("sp_nuevo_codigo", conexionOK))
{
  cmd.CommandType = CommandType.StoredProcedure;

  cmd.Parameters.Add("@P1", SqlDbType.VarChar).Value = valor1.Text;
  cmd.Parameters.Add("@P2", SqlDbType.VarChar).Value = valor2.Text;

  con.Open();
  cmd.ExecuteNonQuery();
}
    
answered by 22.06.2017 в 16:50