title: Execute stored procedure from c#
body: <p>I have c# code which executes properly on my local machine but unable to execute it on server machine.</p>
  
  <p>In my code, I am calling SQL stored procedure in c# as, (c# code 1)</p>
  
  <pre><code> int res = db.Database.ExecuteSqlCommand("exec UpsertUser @OrgUnitId, @ExtUserId, @IntUserId, @IsTestUser, @KronosId",
                                      new SqlParameter("@OrgUnitId", Fac),
                                      new SqlParameter("@ExtUserId", id),
                                      new SqlParameter("@IntUserId", IntUserId),
                                      new SqlParameter("@IsTestUser", DBNull.Value),
                                      new SqlParameter("@KronosId", TenetId)
                                      );
                                  }
  </code></pre>
  
  <p>(In above code I also tried 0 instead of DBNull.value.)
   Related stored procedure's parameter in SQL db is,</p>
  
  <pre><code>    ALTER procedure [dbo].[UpsertUser]
  @OrgUnitId int = null,
  @ExtUserId varchar(50) = null,
  @IntUserId varchar(50) = null,
  @IsTestUser int = NULL,
  @KronosId VARCHAR(10) = NULL,
  @MIPFlag TINYINT =NULL
  
  AS
  </code></pre>
  
  <p>Both codes are also same on local and on server.</p>
  
  <p>BUT, if I change the sequence of parameter in SQL db and put kronosId before IstestUser, and change stored procedure in c# to,</p>
  
  <p>C# modification: code 2</p>
  
  <pre><code> int res = db.Database.ExecuteSqlCommand("exec UpsertUser @OrgUnitId, @ExtUserId, @IntUserId, @KronosId",
                                  new SqlParameter("@OrgUnitId", Fac),
                                  new SqlParameter("@ExtUserId", id),
                                  new SqlParameter("@IntUserId", IntUserId),
                                  new SqlParameter("@KronosId", TenetId)
                                  );
  </code></pre>
  
  <p>then it works on server as well.</p>
  
  <p>Am I missing something in my  c# code 1?</p>
  
  <p>Thanks for help.</p>