Bug 21172

Summary: text field type nvarchar(max) is truncated to 4000 chars
Product: [Mono] Installers Reporter: kakamatyi <kakamatyi>
Component: GeneralAssignee: Bugzilla <bugzilla>
Severity: normal CC: bsansregret, chrisntr, dominic, jon.goldberger, mono-bugs+mono, pj.beaman, vargaz
Priority: ---    
Version: unspecified   
Target Milestone: 3.12.0   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Bug Depends on:    
Bug Blocks: 24173    

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.