Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any clever way to fix 'string or binary data would be truncated' warning with LINQ

Is there a clever way to determine which field is causing 'string or binary data would be truncated' with LINQ.

I've always ended up doing it manually by stepping through a debugger, but with a batch using 'SubmitChanges' I have to change my code to inserting a single row to find the culprit in a batch of rows.

Am I missing something or in this day and age do I really have to still use a brute force method to find the problem.

Please dont give me advice on avoiding this error in future (unless its something much cleverer than 'validate your data'). The source data is coming from a different system where I dont have full control anyway - plus I want to be lazy.

PS. Does SQL Server 2008 actually tell me the field name. Please tell me it does! I'll upgrade!

like image 858
Simon_Weaver Avatar asked Nov 20 '08 19:11

Simon_Weaver


2 Answers

Fire up SQL Profiler. The last query from your application should be the one that is failing.

like image 117
Kip Avatar answered Nov 09 '22 14:11

Kip


Seems like they fixed this problem for the Service Pack 1 of .NET 3.5, as noted in this link: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=353232

Might want to check it out yourself.

like image 34
alextansc Avatar answered Nov 09 '22 14:11

alextansc