0

I have a flat-file SQL Server database. I'm trying to insert info into the table but I keep getting "String or binary data would be truncated" errors every time I run it. ALL of my text fields are nvarchar(max), but it still throws the error and I can look at the data, and nothing is over 8192 characters. I don't think anything is over 256, to be honest.

Any ideas?

I'm using Visual Studio 11 and Entity Framework 4 if that matters.

2
  • I would diagnose this by removing fields until it works then you can look at the actual field which has an issue.
    – undefined
    Aug 24, 2012 at 2:40
  • I would use SQL profiler and capture the problematic query. Then you can check what fields are passed as string and if parameter for string has correct length. Aug 24, 2012 at 8:02

1 Answer 1

0

SQL Server 2019 should produce a different error message that contains the table and the column that causes the conflict

Error message ID 8152 has been replaced with error 2628 to now include the column and string value that would be truncated. “String or binary string would be truncated in table , column . Truncated value: ”

See also https://blogs.msdn.microsoft.com/sql_server_team/string-or-binary-data-would-be-truncated-replacing-the-infamous-error-8152/

Note that for now, even in SQL Server 2019 CTP 2.0 the same trace flag 460 needs to be enabled. In a future SQL Server 2019 release, message 2628 will replace message 8152 by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.