SQL nvarchar text fields being randomly cut off, HELP!

I have a column in the database for storing details abotu the record. Users input large amounts of plain text (usually a  paragraph or so). The column data type is set to nvarchar(MAX), but lately we're noticing that some of these text entries are being randomly cut off. I have no idea what could be causing this. I'm not sure if it's user error or I'm doing something wrong. Is there anything I should be doing other than setting the data type to nvarchar(MAX)? They're entering data into this particular column with a multiline textbox with wrap set to true if that matters.

I'm under a bit of pressure over this and could really use some help.
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
varchar/nvarchar(max) is perfectly ok.
if the data is "cut", it's either on saving or on displaying where it get's "cut" or truncated.
you need to debug on which place it does occur, first check out the saving.

to check, after the insert/update, the column has the proper lenght, check the len() and/or datalength() functions ...
cant you set it to type Text?
Are you using a control for output which supports line breaks? May be the data is in the field but not being displayed properly. Show us the code being used to save/retrieve the value.
DBAduck - Ben MillerPrincipal ConsultantCommented:
It will depend on how you are seeing them cut off.  If you are just querying them in SSMS then you have to know that there is a limit of 8000 characters in text fields (nvarchar(max) as well) so you may not see what you think you should.

The best way to tell if it is being cut off is to use the DATALENGTH() function on the field when selecting out of it.

FROM tablename

This will tell you how long the maximum column is and if it is > 8000 then I would find out the id to that row (Primary Key so that you can query it and see) and validate that it is not cut off.

The other thing you should check is how you defined the inserting or updating of that field in code.  The value for MAX in the length is -1.  So if you are using a SqlParameter then you would set the type to NVarChar and the length to -1.
asphaltninjaAuthor Commented:
It appears as if it was a problem with the way it was saving data.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.