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

后端 未结 4 2436
暗喜
暗喜 2021-02-20 16:42

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 thr

相关标签:
4条回答
  • 2021-02-20 17:04

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

    0 讨论(0)
  • 2021-02-20 17:22

    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.

    0 讨论(0)
  • 2021-02-20 17:22

    It would probably be useful to re-post/edit this tagged as linq .net

    DJ - where are you getting this data you post as a proposed solution ?

    The exception doesn't contain this information, so your post is pretty much useless - unless you can specify the source.

    0 讨论(0)
  • 2021-02-20 17:23

    Assuming you are processing a large batch of records and you don't want to (can't) validate the data before hand and you just want db constraints to catch any errors?

    Change your program to catch the exception and print out the current record details to a log file or something.

    Record # 9999
    Caused "string or binary data would be truncated" error
    Field1: "Data" Length: 55
    Field2: 9999
    etc.
    
    0 讨论(0)
提交回复
热议问题