1

I have an strange behavior in a web application that started happening this week. Even when it worked before I cannot retrieve InputOutput parameters from Sql Server anymore. Syntax in nearly all procedures is the same, I need to retrieve Identity values from tables to continue the process.

SqlParameter paramId = new SqlParameter("@Id", objMyValueId);
paramId.Direction = ParameterDirection.InputOutput;

After executing the SP with ExecuteNonQuery I always get null values (or any value set in InputOutput parameter).

paramId.Value --> (Always null)

It's like collection remains still and it can't be modified. Is there any setting in Sql Server or configuration parameter into a connection string that could affect this behavior? It happens in every stored procedure I execute and it worked before.

4
  • objMyValueId shouldn't that be a DBType of some sort int, varchar, etc..? also show more of your code and I would look up using Parameter.AddWithValue` method vs using SqlParameter also where are you adding the SqlParameter you should look at this SO posting for a good example on what to do stackoverflow.com/questions/8148815/… Commented Aug 15, 2013 at 15:00
  • @DJKRAZE: I don't believe you can get output when using AddWithValue. Commented Aug 15, 2013 at 15:02
  • I trimmed the code on purpose because it's not relevant in this case. It's a website that worked for a year, I added two new procedures and now every single query doesn't retrieve InputOutput parameters. I haven't changed anything into the core of the application, seems to be an unexpected behavior so that's why I ask if there's something external (config, settings in Sql Server and so worth) that can affect it. Commented Aug 15, 2013 at 15:02
  • zimdanen yes you can perhaps you are not familiar with how to do that Commented Aug 15, 2013 at 15:06

1 Answer 1

0

Well, I came to the conclusion (finally) it was our fault and the error is clear. After tracking back commits in SVN I found somebody of the team included a new feature into the core of the database interaction assembly. To avoid repeating some code in the data layer most of the parameters are inferred from the .net type. It keeps it simple and separates the layer of the engine (Sql Server, Oracle, mySql, etc) In one of the commits an override to parameter insert function was made, it causes we lose "Direction" value due to an incorrect cloning. So that's the problem, I found it including source code of the database layer and debugging into the exact injection of parameters into the command, there I could see Direction value was lost. Thanks all for your help, I always appreciate how much this community helps me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.