NHibernate is truncating long strings when saving

.net, nhibernate, sql-server-2008, ssms

Solution

As noted in the comments in the OP's question, the issue was in `SSMS` displaying the data.

There is a known bug in `Sql Server Management Studio 2008` that you cannot paste more than 43679 characters from a column in Grid Mode.

Options (Query Results/SQL Server/Results to Grid Page) version SQL Server 2008 R2

The maximum characters retrieved in Grid Mode for non XML data should be 65535 characters.

Severals ways have been discussed to display the `XML` through `SSMS`:

Set Maximum Characters Retrieved to `XML` data and set the limit to Unlimited.

Try casting the result to `XML`, i.e. `cast(COLUMN_NAME as XML)`

- Breaking output of column to multiple rows

- Copy-paste column to another program

- Third party tooling (ssmsboost)

Alternatively, these discussions might be useful:

https://stackoverflow.com/a/5508193/368552, https://stackoverflow.com/a/2760023/368552

Problem

I am having issues saving very long strings to the database using `NHibernate`. The strings are being truncated to 43,680 characters. The string is a very long `XML` packet that varies in size, but sometimes is very long. The database data type is `nvarchar(max)` so the limitation is not there. Can somebody help me understand why `NHibernate` is truncating this, and how I can prevent it? Here is my mapping: ``` <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Application.DataObjects" namespace="Company.Application.DataObjects.Transaction.Domain"> <class name="TransactionDO" table="Transactions"> <id name="TransactionID"> </id> <property name="Created" /> <property name="LongXML" type="StringClob"> <column name="LongXML" sql-type="nvarchar(max)"/> </property> <property name="ProcessConstructor" /> <property name="VeryLongXML" type="StringClob"> <column name="VeryLongXML" sql-type="nvarchar(max)" /> </property> </class> </hibernate-mapping> ```

Original source

Related problems