title: MVC -String or binary data would be truncated.\r\nThe statement has been terminated
body: <p>I understand that this error means that I am trying to insert a value that is larger than what I allow in my database but I cannot see which value is causing the problem</p>
  
  <p><strong>This is where I am inserting the data:</strong></p>
  
  <pre><code>UserActivity log = new UserActivity();
  
  ApplicationDbContext db = new ApplicationDbContext();
  
  log.UserEmail = User.Identity.Name;
  log.SQL_Query = queryString;
  log.Query_Start = String.Format("{0:hh:mm:ss}", start);
  log.Query_End = String.Format("{0:hh:mm:ss}", end);
  log.Query_Time = String.Format("{0:mm:ss.ff}", Duration.ToString());                   
  
  db.UserActivities.Add(log);
  
  db.SaveChanges();
  </code></pre>
  
  <p><strong>This is the database table definition:</strong></p>
  
  <pre><code>CREATE TABLE [dbo].[UserActivities] (
      [Id]            INT            NOT NULL,
      [UserEmail]     VARCHAR (255)  NOT NULL,
      [SQL_Query ]    VARCHAR (1000) NOT NULL,
      [Query_Start]   VARCHAR (11)   NULL,
      [Query_End]     VARCHAR (11)   NULL,
      [Query_Time]    VARCHAR (11)   NULL,
      [Error_Message] VARCHAR (255)  NULL,
      PRIMARY KEY CLUSTERED ([Id] ASC)
  );
  </code></pre>
  
  <p><strong>In the debugger I using the length command to look at the length of the values I am passing in, this was my results:</strong></p>
  
  <pre><code>        log.UserEmail.Length;
          21
          log.Query_End.Length;
          8
          log.Query_Start.Length;
          8
          log.SQL_Query.Length;
          32
  </code></pre>
  
  <p><strong>This is a sample of the data that would be entered</strong>
  <a href="https://i.stack.imgur.com/OvdRt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OvdRt.png" alt="enter image description here"></a></p>
  
  <p><strong>This is the UserActivity class</strong></p>
  
  <pre><code>public class UserActivity
  {
      [Key]
      public int Id { get; set; }
      public string UserEmail { get; set; }
      public string SQL_Query { get; set; }
      public string Query_Start { get; set; }
      public string Query_End { get; set; }
      public string Query_Time { get; set; }
      public string Error_Message { get; set; }
  }
  </code></pre>