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.
asphaltninjaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

urir10Commented:
cant you set it to type Text?
0
Guy Hengel [angelIII / a3]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 ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
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.
0
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.

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.
0
asphaltninjaAuthor Commented:
It appears as if it was a problem with the way it was saving data.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.