title: Executing a stored procedure yields an error saying it's expecting a parameter that I have supplied?
body: <p>I've written a piece of c# code which executes a stored procedure on an MS SQL box. I Create the SP like so:</p>
  
  <pre><code>SqlCommand command = new SqlCommand(creditLimitRequestSP, connection);
  command.CommandType = System.Data.CommandType.StoredProcedure;
  </code></pre>
  
  <p>I then create a set of parameters using the constructor for the parameters:</p>
  
  <pre><code>SqlParameter p1 = new SqlParameter(p1, p1Value);
  vdnParam.Size = 7;
  </code></pre>
  
  <p>Some of my parameters are integers in which case I parse them like so:</p>
  
  <pre><code>int p4Value = 0;
  bool parsedP4 = Int32.TryParse(p4AsAString, out p4Value);
  SqlParameter p4;
  if (parsedP4)
  {
      p4 = new SqlParameter("@p4", SqlDbType.Int, p4Value);
      p4.Size = sizeof(Int32);
  }
  else
  {
      throw new InvalidFieldDataException("p4", p4AsString);
  }
  </code></pre>
  
  <p>Then after I've parsed the parameters from a dictionary I add them like so:</p>
  
  <pre><code>command.Parameters.Add(p1);
  command.Parameters.Add(p2);
  command.Parameters.Add(p3);
  command.Parameters.Add(p4);
  command.Parameters.Add(p5);
  command.Parameters.Add(p6);
  </code></pre>
  
  <p>When I execute the stored procedure I get an exception telling me is is expecting a parameter which I have added to the command. Why would it do this?</p>
  
  <p>Initially I thought this might be because the parameters were being added in the wrong order but I changed them to match the order in the Stored procedure (event though it shouldn't matter as I'm using named parameters) and it didn't resolve anything.</p>
  
  <p>The parameter in question does not have a default value in the SP, and it an integer value.</p>