Maximum Length Exceeded

Mike-E-angelo 521 Reputation points
2024-11-22T14:57:18.8166667+00:00

I am seeing the following error in my logs:

EntityFramework.Exceptions.Common.MaxLengthExceededException: Maximum length exceeded ---> Microsoft.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated in table 'dbo.Profile', column 'ImagePath'. Truncated value: 'https://lh3.googleusercontent.com/a-/ALV-<omitted>'.

Note that the "truncated value" is omitted but the characters of the provided string as emitted in the logs are only 100 characters long.

When I look at the table, it is an nvarchar(1024):

User's image

If the truncated string is 100 characters, and the column allows 1024 characters, why am I seeing this error?

Thank you for any assistance you can provide.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
757 questions
Azure SQL Database
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,663 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 112.8K Reputation points MVP
    2024-11-22T22:14:33.8566667+00:00

    So in the SQL code which you run, you are apparently trying to squeeze in something which is longer than 100 characters in something that only fits 100 characters. (And the message only shows the truncated value.)

    To find out where this might be happening, you could set up an extended-event session which captures exceptions and also captures the statement. I have article on my web site, Monitor Exceptions in Your Database, which shows how to set up such a session, and which also includes a view to easily query the output from the session.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Viorel 118.4K Reputation points
    2024-11-23T11:03:25.42+00:00

    It seems that “Truncated value” from the error messages should be interpreted as “The first 100 characters of the truncated value”, regardless of the size of the column.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.