String or binary data would be truncated.

Thread Solved
Reply

Join Date: Dec 2008
Posts: 21
Reputation: NextCom is an unknown quantity at this point 
Solved Threads: 0
NextCom NextCom is offline Offline
Newbie Poster

String or binary data would be truncated.

 
0
  #1
Jul 2nd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,132
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 551
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: String or binary data would be truncated.

 
0
  #2
Jul 2nd, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: NextCom is an unknown quantity at this point 
Solved Threads: 0
NextCom NextCom is offline Offline
Newbie Poster

Re: String or binary data would be truncated.

 
0
  #3
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,132
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 551
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: String or binary data would be truncated.

 
0
  #4
Jul 2nd, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: NextCom is an unknown quantity at this point 
Solved Threads: 0
NextCom NextCom is offline Offline
Newbie Poster

Re: String or binary data would be truncated.

 
0
  #5
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC