Batch update returned unexpected row count

2,412 views
Skip to first unread message

olaf

unread,
Jun 14, 2010, 12:31:15 PM6/14/10
to nhusers
Hello,

if I insert a new row in a table, a trigger runs that inserts another
row in a different table.

In NHibernate I get this error: "Batch update returned unexpected row
count from update; actual row count: 2; expected: 1".

I think because of the trigger SQL Server returns 2 instead of 1, what
is correct. However, is there any way to make SQL Server to return 1
without removing the trigger or can I disable the check in NHibernate?
What's the correct way to handle this issue?


Regards
Olaf

Robert Rudduck

unread,
Jun 14, 2010, 12:47:24 PM6/14/10
to nhu...@googlegroups.com
Have your trigger turn NOCOUNT ON then after completion NOCOUNT OFF.

So:

SET NOCOUNT ON

... Trigger Code ...

SET NOCOUNT OFF

That should work IIRC.

- Robert


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


olaf

unread,
Jun 14, 2010, 1:39:00 PM6/14/10
to nhusers
Great! That works.

But if someone adds a new trigger without that flag, NHibernate may
fail again. Is there any way to set NOCOUNT ON for triggers by
default?

Regards
Olaf
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com­>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Fabio Maulo

unread,
Jun 14, 2010, 1:50:33 PM6/14/10
to nhu...@googlegroups.com
If you can unit-test for a SP you can check it

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

olaf

unread,
Jun 14, 2010, 2:51:08 PM6/14/10
to nhusers
For SQL Server it's only possible to set that option for the SQL
Server instance. It's not possible to specify the option only for
triggers in one database.

I've have tried to set that option for the server instance. In that
case SQL Server never returns a count and NHibernate would fail again.
Anyway, it's not a good idea to set NOCOUNT for the whole server, so I
have to ensure that each trigger uses NOCOUNT ON.


Thanks for your help
Olaf
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Bunsubscribe@googlegroup­s.com>
> > ­>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.-Zitierten Text
> > ausblenden -
>
> > > - Zitierten Text anzeigen -
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com­>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo- Zitierten Text ausblenden -
Reply all
Reply to author
Forward
0 new messages