943,520 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 9120
  • MS SQL RSS
Jul 2nd, 2009
0

String or binary data would be truncated.

Expand Post »
Error message ”[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.” comes when you insert/update a larger value than the column is specified for. But is there a way to detect what column, or what value that is to large?

I’m thinking about splitting up the INSERT string, and checking the length of all the char/varchar columns that is specified schema, and doing a LEN on the value to see if it’s larger than the length specified in the schema. But is there an easier way?
Similar Threads
Reputation Points: 18
Solved Threads: 0
Light Poster
NextCom is offline Offline
26 posts
since Dec 2008
Jul 2nd, 2009
0

Re: String or binary data would be truncated.

No. The easiest way I have ever come up with handling this is to have all of the database information embedded in the calling application and check the data lengths before i do an update/insert. I have no idea why Microsoft did not include the column information but that is a very annoying error that can be hard to solve.

You can check the data in TSQL before your update/insert and call raiserror() if the data is too long but I personally find it easier to handle in code.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jul 2nd, 2009
0

Re: String or binary data would be truncated.

Damit, then I have to try to make the matching in the schema with the split, LEN and match, just to do the debugging a bit easier.

If it was possible to get the exact column, I would like to build in an automatic ALTER on the table, which extends the length of the column. But I don't have the guts to start with that when I’m not 100% sure it's the right column.
Reputation Points: 18
Solved Threads: 0
Light Poster
NextCom is offline Offline
26 posts
since Dec 2008
Jul 2nd, 2009
0

Re: String or binary data would be truncated.

That just sounds like a bad idea... You don't want to automatically start making schema alterations like that. There is some overhead and additional development time required to catch those bad inserts before they happen but I think that is about as far as you should go. There is an option to turn off this behavior and automatically truncate the string and insert it anyways... but I think that is a bad idea too. You want to enforce data integrity and this undermines that practice.

Sorry I couldn't have a straight forward answer for you. Please mark this thread as solved if I have answered your question.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jul 2nd, 2009
0

Re: String or binary data would be truncated.

Solved, because i don't think there is any "good" solution for the problem.

I was thinking of making the automatical extension of schema based on user rights, because our customers have diffrent needs.
When an administrator recives this error message, then he just clicks one button and it automaticly extends the lenght. Without the need of contacting us.
Reputation Points: 18
Solved Threads: 0
Light Poster
NextCom is offline Offline
26 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: joining the table
Next Thread in MS SQL Forum Timeline: The INSERT statement conflicted with the FOREIGN KEY constraint





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC