SQLException : String or binary data would be truncated

前端 未结 12 887
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 06:41

I have a C# code which does lot of insert statements in a batch. While executing these statements, I got \"String or binary data would be truncated\" error and transaction r

12条回答
  •  难免孤独
    2020-11-27 07:12

    With Linq To SQL I debugged by logging the context, eg. Context.Log = Console.Out Then scanned the SQL to check for any obvious errors, there were two:

    -- @p46: Input Char (Size = -1; Prec = 0; Scale = 0) [some long text value1]
    -- @p8: Input Char (Size = -1; Prec = 0; Scale = 0) [some long text value2]
    

    the last one I found by scanning the table schema against the values, the field was nvarchar(20) but the value was 22 chars

    -- @p41: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [1234567890123456789012]

提交回复
热议问题