title: MS SQL Can't update table
body: <p>I have a one column table to keep track of number of visits. In Global.asax.cs I attempt to increment this value by 1 inside application_start but the field does't get updated. I get no exceptions but number of rows affected is always zero.</p>
  
  <p>I tried the same simple query in SSMS and I get the same thing: 0 rows affected.
  There is one int column in that table called NumVisits. 
  This is part of Application_Start in Global.asax.cs:</p>
  
  <pre><code>Application.Lock();
  int iNumVisits = SomeClass.GetNumVisits();
  SomeClass.UpdateNumVists(iNumVisits + 1);
  Application.UnLock();
  </code></pre>
  
  <p>This is in SomeClass (BLL):</p>
  
  <pre><code>public static void UpdateNumVists(int iNumVisists)
  {
      LocaleRepository oLocaleRepository = new LocaleRepository(new SqlDbContext());
      oLocaleRepository.UpdateNumVists(iNumVisists);
  }
  </code></pre>
  
  <p>and this is in DAL:</p>
  
  <pre><code>public void UpdateNumVists(int iNumVisits)
  {
      int iRet = 0;
      try
      {
          dbContext.Open();
          List&lt;SqlParameter&gt; spParams = new List&lt;SqlParameter&gt;();
          string sQuery = "update Visits set NumVisits = @NumVisits";
          spParams.Add(dbContext.CreateSqlParam("@NumVisits", SqlDbType.Int, 0, iNumVisits));
          dbContext.ExecuteSqlNonQuery(sQuery, spParams, ref iRet);
      }
      catch (Exception e)
      {
          throw e;
      }
      finally
      {
          dbContext.Close();
      }
      return;
  }
  </code></pre>
  
  <p>I use the following for all commands using executeNonQuery:</p>
  
  <pre><code>public void ExecuteSqlNonQuery(string sQuery, List&lt;SqlParameter&gt; spParams, ref int iRet)
  {
      using (SqlCommand command = new SqlCommand())
      {
          command.CommandType = CommandType.Text;
          command.Parameters.AddRange(spParams.ToArray&lt;SqlParameter&gt;());
          command.Connection = DbConnection;
          command.CommandText = sQuery;
          try
          {
              iRet = command.ExecuteNonQuery();
          }
          catch(Exception e)
          { }
      }
  }
  </code></pre>
  
  <p>when the update command is executed, iRet is zero. I can't see why a simple update query would not work.</p>
  
  <p>This is the create script I got from SSMS:</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE TABLE [dbo].[Visits](
      [NumVisits] [int] NULL
  ) ON [PRIMARY]
  
  GO
  </code></pre>