title: DbUpdateException: Which field is causing "String or binary data would be truncated"
body: <p>I am getting a <code>DbUpdateException</code> with message </p>
  
  <blockquote>
    <p>String or binary data would be truncated</p>
  </blockquote>
  
  <p>I understand that one of the fields in the entity won't fit the length of the column in the database. And that I could go down and check them manually.</p>
  
  <p>What I am trying to do however, is get a sensible error message which might tell me which field it actually is! E.g. </p>
  
  <blockquote>
    <p>String or binary would be truncated at field ProspectName.</p>
  </blockquote>
  
  <p>I am able to print out a lot of random information. and have tried various stuff. But nothing points to the field name.</p>
  
  <p>Please note this is <strong>NOT</strong> of type <code>DbEntityValidationException</code>, it is a <code>DbUpdateException</code>  </p>
  
  <pre><code>// DbUpdateException exception
  foreach (var entry in exception.Entries)
  { 
      builder.AppendLine(String.Format("Error at: Type {0}", entry.Entity.GetType().Name));
  
      if ((exception.InnerException is System.Data.Entity.Core.UpdateException) &amp;&amp;
          (exception.InnerException.InnerException is System.Data.SqlClient.SqlException))
      {
          var updateException = (System.Data.Entity.Core.UpdateException)exception.InnerException;
  
          var sqlException = (System.Data.SqlClient.SqlException)exception.InnerException.InnerException;
          var result = new List&lt;ValidationResult&gt;();
  
          for (int i = 0; i &lt; sqlException.Errors.Count; i++)
          {
              builder.AppendLine(String.Format("Error code: {0} ", sqlException.Errors[i].Number));
              builder.AppendLine(String.Format("Source: {0} ", sqlException.Errors[i].Source));
              builder.AppendLine(String.Format("Message: {0} ", sqlException.Errors[i].Message));
              builder.AppendLine(String.Format("State: {0} ", sqlException.Errors[i].State));
              builder.AppendLine(String.Format("Procedure: {0} ", sqlException.Errors[i].Procedure));
          } 
      }
  }
  </code></pre>
  
  <p>Complete error:</p>
  
  <blockquote>
    <p>String or binary data would be truncated. The statement has been terminated.   </p>
    
    <p>Error at: Type tree_1ECACDBB4458C7A9DEC7CD183FD8B8C3473502FEFFACF160E17AD47718DCE5EA<br>
    Error code: 8152<br>
    Source: .Net SqlClient Data Provider<br>
    Message: String or binary data would be truncated.<br>
    State: 14<br>
    Procedure:<br>
    Error code: 3621<br>
    Source: .Net SqlClient Data Provider<br>
    Message: The statement has been terminated.<br>
    State: 0<br>
    Procedure:</p>
  </blockquote>