State of knowledge

March 2022

Observation

The field content of certain data fields from Microsoft SQL Server (established with 2012) is reduced to half.

Possible reason

The cause could be an error in the ODBC driver.

Columns of type nvarchar(max) * or varchar(max) * are affected.

* max' is a keyword and does not stand for a placeholder, i.e. a number!

During the readout, a type SQL_LONGVARCHAR is supplied instead of SQL_WLONGVARCHAR, or SQL_VARCHAR instead of SQL_WVARCHAR, which has the consequence that the field lengths and thus the contained text is halved.
In summary: Unicode text comes with ANSI flag and is therefore halved when copied.

See also:

http://msdn.microsoft.com/en-us/library/ms714102(v=vs.85).aspx

Procedure/Solution/Workaround

Apply different or fixed size data types in the database table or create a view and use it if the table is to remain unchanged.
e.g. select id, CAST(varcharmaxcolumn AS varchar(1024)) AS varchar1024column from ...

Bugfix can now be enabled via RegistryKey: KEY_LOCAL_MACHINE\Software(Wow6432Node)ESTOS\\MetaDirectory3.5\Diagnostic\ DWORD "OldODBCDriver" : 1

The bugfix works only for some, not for all Microsoft SQL drivers. Workaround should work for all.