I'm debugging an intermittent truncation error in my application. The error in my logs looks like this:
System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated. Generated: Tue, 02 Nov 2010 03:55:18 GMT
NHibernate.Exceptions.GenericADOException: could not insert:
[DataModel.Product][SQL: INSERT INTO [Product] (Fields) VALUES (?, ?,...);
select SCOPE_IDENTITY()] --->
System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
Notice that the error does not provide parameter values for the sql that threw the error, only placeholders: (?, ?,...). Is there a way to get these from nHibernate? Something like this:
try {
...
Session.Flush(); // throws
}
catch (GenericADOException ex) {
// want to get the bad parameter values,
// so I can re-throw a more helpful exception
}