How to troubleshoot Entity Framework SQL Error Exception “String or binary data would be truncated”

If you get this error, it means you are trying to insert data of a length larger than the max length of a data column.  For example, you may be inserting “San Francisco” to city varchar(10).

Now, the problem is identify which column is the culprit. I don’t see a way to determine the column from the run time exception.

So you can try 2 other ways:

  1. Examine each field length of the entity being inserted and compare against the database schema.
  2. Use SQL Profiler to capture the SQL statement.  Then you could examine the length of each insert value.  Or you can use the process of elimination by setting each insert value to an empty string until your insert statement executes without error.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s