So I have been dealing with this intermittent error and have not been able to figure out why it happens. My guess is that some buffer gets full during a transaction at the SQL Server side and results on this error. I have a table that contains 3 columns with sql type varchar(max) and an id column defined as an identity column. When I run my code:
nhsession.Save(audit); I get the following error: ERROR NHibernate.AdoNet.AbstractBatcher [(null)] - Could not execute query: INSERT INTO Audit (TypeId, NotificationTime, Message, StackTrace, MessageId, TransactionId, MessageBodyType, SourceTypeId, MessageHeaders, MessageBody, MessagePayload, Hostname) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11); select SCOPE_IDENTITY() System.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) Now I noticed that the call that initiated this error is NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) so I was wondering why is doing an execute reader on an insert statement. It occurred to me that the reason is the statement select SCOPE_IDENTITY(). I turned on debug logging on NHibernate, took the complete statement and attempted to run it in SQL Server management studio. It seems the insert statement succeeds but the select SCOPE_IDENTITY() statement fails with this error. The record actually gets inserted in the database when I run it on management studio but since it is wrapped in a transaction in my code, the transaction gets rolled back. So I have two questions: 1. Is it possible to do a session.Save(object) on an object whose mapping defines the id column as an identity on sql server, to not add the select SCOPE_IDENTITY() statement at the end of the insert? 2. Is there a way to prevent this exception to be thrown an to let NHibernate handle this as a no error? The error suggests that there is a size issue with the data that I am attempting to insert but that is misleading so perhaps there is some setting on SQL Server to increase the buffer size of a transaction??? Are there any other suggestions as to how to deal with this issue? Thanks. Miguel. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/1vuN4M-pPlMJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
