0

I'm working on an app written in C# (VS2013). It's calling a stored procedure in SQL Server. It's passing a bunch of input parameters, plus four output parameters.

My problem is that one of these output parameters is getting passed with a value that I'm not setting.

This is what SQL Server Profiler records as the procedure call. I've replaced the actual parameter names with generic names just for asking this question.

declare @p51 int
set @p51 = 300000

declare @p52 int
set @p52 = NULL

declare @p53 int
set @p53 = 7776

declare @p54 int
set @p54 = NULL

exec [dbo].[proc_name] (input param list is here)
     @outparam1 = @p51 output, @outparam2 = @p52 output,
     @outparam3 = @p53 output, @outparam4 = @p54 output

@outparam3/@p53 is the issue. It shouldn't have a value. It's being created with a null value like this (even though as an output parameter that shouldn't be necessary):

var spParam3 = new SqlParameter("@outparam3", SqlDbType.Int);
spParam3.Value = DBNull.Value;

There's nothing between that line of code, and the stored procedure execution, that's setting a different value for the parameter. I've set a breakpoint on the ExecuteNonQuery() call, checked the parameter list, and that parameter was still null.

I'm completely lost on why its value is getting set to 7776. Yes, that number is a code used throughout the app, but I can't tell how or why this parameter is getting set to that value.

Any thoughts on where this is happening would be greatly appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    A stored procedure in the sql server. – jdweng Sep 05 '16 at 03:04
  • This is technically right but I didn't understand it until I found this question: http://stackoverflow.com/questions/2198715/stored-procedure-output-parameters-in-sql-server-profiler – kitchensink108 Sep 06 '16 at 04:27

1 Answers1

0
@outparam3=@p53

@p53 = 7776

thats why the value you get/insert in table is 7776

KyLim
  • 468
  • 1
  • 6
  • 22
  • What I don't understand is where that's coming from. I can't see anywhere in the process (setting up the stored procedure call, setting the parameters, executing the call) where I'm assigning anything the value of 7776. – kitchensink108 Sep 05 '16 at 14:11