Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 577
netwire Avatar asked Nov 21 '25 16:11

netwire


1 Answers

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.

like image 177
user529869 Avatar answered Nov 24 '25 10:11

user529869



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!