NHibernate : Could not insert – Blank Params – String or Binary data would be truncated.

I was using NHibernate when mapping some objects from a legacy system to objects in a new system and had an issue with one of the records failing to save.

The error message was “String or binary data would be truncated. The statement has been terminated.” but when I looked at the SQL being executed against the server the parameters were all question marks – VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?).

The error message was exactly right, the problem was caused by the truncation of data. When I was mapping from my source object to my target object I was inserting a text string which was too long for the property and when NHibernate was saving, the data was being truncated. The question marks in the SQL output threw me though.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s