Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3496968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:18:49+00:00 2026-05-18T12:18:49+00:00

When setting up replication in Sql Server 2008 the system creates triggers on every

  • 0

When setting up replication in Sql Server 2008 the system creates triggers on every replicated table in order to facilitate the transfer of data to the subscribing databases.

Would it be expected behaviour for system generated triggers to use SET NOCOUNT ON to prevent their actions affecting the value of the @@ROWCOUNT function?

Background

I am using NHibernate with a Sql Server 2008 backend database. The database has replication enabled which creates system generated triggers on the published tables to facilitate the data transfer to the subscribers.

Without the replication everything works fine, but with the replication NHibernate’s rows affected verification checks fail. The number of rows that ADO.Net says it has affected appears to include the rows affected by the associated trigger in addition to the rows affected by the command itself.

In the original question I mentioned the @@ROWCOUNT Sql Server function, but what I really mean is the “rows affected” value returned by the ADO.Net ExecuteNonQuery method. I suppose I was working on the assumption (possibly incorrectly) that that latter was fed by the former.

As a temporary solution we have modified the replication triggers to add the SET NOCOUNT ON before any updates and to reverse this after any updates are complete. This solves our problem for the time being, but is not a viable permanent solution. According to advice we have received and common sense, editing the system triggers is not recommended.

This does however suggest to me that we have identified the exact problem. The rows affected by the triggers are getting included in the final rows affected count for the current command. NHibernate expects only a known number of rows to be affected, it doesn’t provision for any unknown (as far as NHibernate is concerned) triggers adding to this count.

We are currently in the process of investigating options that involve extending NHibernate to add capability to deal with or at least suppress this. Our resources include this SO question.

I have also found this post that seems to suggest that system generated triggers would already set the NOCOUNT option to ON by default, negating the need to modify them. This is definitely not the case for us, so I was wondering why this might be.

  1. What is the default situation with regard to the system generated triggers?
  2. Is the behaviour configurable?
  3. Does it depend on the type of replication – merge, transactional?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:18:50+00:00Added an answer on May 18, 2026 at 12:18 pm

    I have not been able to determine the answer to the original question – (should/can/how) Sql Server system generated replication triggers automatically include the SET NOCOUNT ON option.

    Our DBA team suggest the answer is no. They also say (quite rightly) that they will not customise system triggers in production.

    Options left open to me are…

    1. Modify/extend NHibernate to not throw the TooManyRowsAffectedException when a row count mismatch is detected.
    2. Rip out NHibernate and replace with stored procedures and manual mapping to business objects.

    We have chosen option 1.

    My solution was to modify the NHibernate (2.1) Core in the following way…

    1. First I added a new configuration option to control my new behaviour.
    2. Then I modified the signature of the VerifyOutcomeNonBatched and VerifyOutcomeBatched methods from the NHibernate.AdoNet.Expectations class to accept the new configuration value as a parameter. This involved modifying several places where these methods are called.
    3. Finally I modified those two methods so they each throw/suppress the TooManyRowsAffectedException according to the config option.

    I would be interested in any suggested alternative implementations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have SQL Server database setup. We are setting up a replication scenarios where
I'm setting up replication for a server which runs a bunch of databases (one
I've had a tough time setting up my replication server. Is there any program
When setting up foreign keys in SQL Server, under what circumstances should you have
Setting up an integration server, I’m in doubt about the best approach regarding using
The Setting: The program in question tries to post form data via an AJAX
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work
Setting up a Windows based web application on Amazon's cloud has definitely been a
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: <buildpublisher>
When setting up a new virtual directory for hosting a SOAP web service in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.