Monday, April 30, 2012

SQL Server: String or binary data would be truncated.

Msg 8152, Level x, State x, Line x String or binary data would be truncated.

What does this mean?
This is the equivalent of SQL Server telling you that you are trying to fit too much into a container and if you were to do so then something would be left out. As a result, by default SQL Server won't allow this so that is why you are seeing the error.

Solution 1
If you don't want to lose any of your data, then you must increase the size of your column.

Solution 2
If you don't care if data is truncated and just want the message to go away then you must use "SET ANSI_WARNINGS OFF" with each execution of your sql statements with respect to .Net programming. Unfortunately there is no way to turn off this warning at a server or database level, it has to be set per connection. So if you are opening and closing connections with each execution then you must use that statement before executing your statement. I searched long and hard to turn this off at a database level, supposedly there is a way to do it, but all of the things I have tried did nothing.


No comments:

Post a Comment