Link to home
Start Free TrialLog in
Avatar of asphaltninja
asphaltninjaFlag for United States of America

asked on

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.
Avatar of urir10
urir10

cant you set it to type Text?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.

SELECT MAX(DATALENGTH(fieldname))
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.
Avatar of asphaltninja

ASKER

It appears as if it was a problem with the way it was saving data.