Bug 21172 - text field type nvarchar(max) is truncated to 4000 chars
Summary: text field type nvarchar(max) is truncated to 4000 chars
Alias: None
Product: Installers
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: 3.12.0
Assignee: Bugzilla
Depends on:
Blocks: 24173
  Show dependency tree
Reported: 2014-07-08 07:12 UTC by kakamatyi
Modified: 2014-12-04 16:11 UTC (History)
7 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description kakamatyi 2014-07-08 07:12:17 UTC
Create az Sql Server table with nvarchar(max) field and insert into it more than 8000 length string using command 
After the field will contain only 8000 chars... The string will be truncated...

SELECT DATALENGTH(bigfield) AS TEXTFieldSize from bigtable; will return 8000.

The problem occured in mono 3.4, it worked without errors in mono 2.9.10...
Comment 1 kakamatyi 2014-07-08 07:27:08 UTC
The problem occures when:
cmd.Parameters.AddWithValue(par.Key, par.Value);

Using explicit type, it works ok:
cmd.Parameters.Add(par.Key, SqlDbType.NVarChar, -1);
cmd.Parameters[par.Key].Value = par.Value;

It seems that automatic parameter type detection fails....
Comment 2 Benoit Sansregret 2014-08-06 08:29:35 UTC
I'm experiencing the same behaviour with a Mac application.
I tried with Mono 3.6 and the behaviour is the same.
I'm trying to save a xml in a nvarchar  max and it get truncated.

With a little google search I found that a similar bug was fixed in and earlier version of Mono 2.4.x

I can provide a app that reproduce the issue if need be.
Comment 6 Zoltan Varga 2014-10-24 00:29:08 UTC
From looking into the code, the problem seems to be in Tds70:WriteParameterInfo (). Its trying to send the data as as NText type, and it gets truncated to 4000 bytes for some reason. Newer versions of sql server/tds has support for the nvarchar(max) type so we should probably send that, but its pretty hard to understand from the tds spec how this type can be emitted.
Comment 10 Zoltan Varga 2014-10-30 14:41:26 UTC
Fixed in mono master f269254917ea7362bf8248e121303b4756ed6834/mono 3.12 branch a825298e9dbdc5902ba99edeed4dc0f5a62044cb.
Comment 11 PJ 2014-12-04 16:11:55 UTC
Moving to release product/milestone for verification.