Asp.net-mvc – LINQ: System.Data.SqlClient.SqlException: String or binary data would be truncated

asp.net-mvclinq-to-sql

I have a table and am using ASP.NET MVC to create an object and save it. It's been working fine for a while. Somehow, recently, I started getting this error message on the production machine:

System.Data.SqlClient.SqlException: String or binary data would be truncated.

I can't seem to replicate the same error on my development machine. Is there anyway to find out what column is causing this? I'm running MSSQL 2008 R2 Express.

Best Answer

This usually occurs when you're trying to insert data that is longer than the field size defined on SQL Server. You can increase the size of the field in the database to solve the problem. If you're accepting user input and saving it to the database then you should be validating it against the defined maximum size of the database field.