SQL Server 2008, Stored Procedure "out" parameter of type "int" returns null value. - by parth.shah

Status : 

  Not Reproducible<br /><br />
		The product team could not reproduce this item with the description and steps provided.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 641150 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/3/2011 8:13:20 AM
Access Restriction Public


I am executing a stored procedure from my C# .NET application. I am expecting an int value in a "out" parameter of that procedure.

However, sometimes I receive "null" value in that Stored Procedure.

I did confirm using SQL Profiler that the parameter values are passed correctly to the procedure and further the procedure is also getting executed successfully. The "out" variable is properly initialized and we are setting the record count value in that "out" parameter hence it can not be null.

But still on accessing the value of "out" parameter from the .NET app after the execution of the query, I receive null value.

FYI I am using ExecuteNonQuery Statement for executing the above stored procedure.

I am getting this issue once in every five-ten times call to that stored procedure.

This is evolving as a major issue with my application resulting into a blocker.

The issue is very urgent.

Any help would be appreciated.
Sign in to post a comment.
Posted by Microsoft on 5/30/2012 at 12:32 PM
Closing the bug as we have not heard back from you.
Posted by Kathy Lu on 6/20/2011 at 3:22 PM
We've going ahead with closing this Connect bug, since we are not able to reproduce this issue. If you are still seeing this issue, please feel free to re-activate with your repro and we will investigate further.

Kathy Lu
ADO.NET Test Lead
Posted by Nissim Natanov on 5/9/2011 at 10:32 AM

I have tried to reproduce this issue, here is the sample code I am using:

                using (SqlCommand command = new SqlCommand("[DemoProc]", connection))
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@user", "userValue");
                    command.Parameters.AddWithValue("@pwd", "passwordValue");
                    var iretValuePar = command.Parameters.Add("@iretValue", SqlDbType.Int);
                    iretValuePar.Direction = ParameterDirection.Output;


                    int iretValue = (int)iretValuePar.Value;


The return value of this sample code using your stored procedure is not NULL (Console.WriteLine prints the number returned back). In order to receive OUT parameter's value back, the parameter should be defined with exactly the same type and with direction set to Output (see the code).

In order to help you the best, please post your .Net code, we need to know how you declare and use the command and its parameters.

Best Regards,
Nissim Natanov,
ADO.NET Development team
Posted by Luiz [MSFT] on 5/3/2011 at 2:22 PM

Thanks for reporting this issue. We will investigate it and report it back to you.


Luiz Santos