Administration of Immediate-updating Subscribers

The Immediate-updating Subscribers option is integrated seamlessly into both snapshot and transactional replication. These are optional properties of publications and subscriptions and can be enabled using SQL Server Enterprise Manager, or programmatically by using stored procedures or SQL-DMO.

Immediate-updating Subscribers Restrictions

The following restrictions exist with the Immediate-updating Subscribers option:

Data Modification at Subscriber Sites

When modifying data at Subscriber sites using the Immediate-updating Subscribers option, consider the following issues:

Configuration Modes

The Immediate-updating Subscribers option supports either dynamic RPC mode or static RPC mode for the 2PC connection from the synchronization triggers back to the Publisher. In dynamic RPC mode, synchronization triggers connect dynamically to the Publisher, using a supplied server name, login, and password. This mode offers increased security for users who do not want a statically-defined linked server/remote server connection from a Subscriber to Publisher. It is also easier to use when setting up push subscriptions because the Publisher does not have to be predefined at the Subscriber. In static RPC mode, synchronization triggers connect to the Publisher over a statically-defined server name defined as a linked server or remote server in the sysservers table. This entry is added by an administrator at the Subscriber server.

The configuration mode is set automatically when creating push or pull subscriptions:

User-defined Triggers

If you are adding user-defined, cascading triggers to tables that are published and allow immediate-updating Subscribers, you can place the triggers at either the Publisher or Subscriber. Adding the triggers at the Publisher requires no special programming considerations. For example, you may have two tables, customer and orders, where customerid is a primary key in the customers table and a foreign key in the orders table. You can use a user-defined trigger on the customers table to cascade changes to the customerid in the orders table. Updating the customerid in the customers table at the Subscriber causes the immediate-updating trigger to propagate the update to the Publisher. When the update is applied to the Publisher, the user-defined trigger fires at the Publisher, and cascades the update to the orders table at the Publisher. When the Distribution Agent runs, the update to the orders table is propagated down to the Subscriber. The cascaded changes get reflected accurately at the Subscriber, but with some latency because the orders table is not immediately up to date.

If your application requires that the cascaded table at the Subscriber immediately reflect the change in the cascading table (that is, avoid the latency of the round-trip to the Publisher), you also can add the cascading triggers at the Subscriber. However, when you add user-defined triggers at both the Publisher and the Subscriber, both sets of triggers must be created using the NOT FOR REPLICATION option. With the NOT FOR REPLICATION option active, an update to one of the tables at the Subscriber is cascaded to the other table by the user-defined trigger and then propagated to the Publisher by the immediate-updating triggers on each table. Because the user-defined cascading triggers at the Publisher are marked NOT FOR REPLICATION, those triggers do not fire.


Note SQL Server replication does not support the automatic transferring of triggers from the table at the Publisher to the table at the Subscriber. All user-defined triggers must be created manually at the Publisher and Subscriber.


You can also add user-defined triggers to update columns in the row currently being modified. Programming insert and update triggers is challenging because the immediate-updating triggers may also need to update the same row. For example, an immediate-updating trigger must insert the new timestamp or identity value received from the Publisher as part of a two-phase-commit transaction. If both the user-defined trigger and the immediate-updating trigger apply an update to the same row and you have not included a subroutine for special case handling, the transaction could terminate. Without special handling, the update process continues in a loop with each trigger update firing the other trigger until the maximum nesting level (32) is reached and the transaction terminates. To avoid this situation, you must allow immediate-updating insert and update triggers to fire before any user-defined triggers. The user-defined trigger should determine if it is being fired in the context of a immediate-updating trigger and, if so, terminate without firing. Add the following lines of code to the beginning of the your trigger:

DECLARE @retcode int, @trigger_op char(10)

EXEC @retcode = sp_check_for_sync_trigger @table_id, @tablename sysname, @trigger_op OUTPUT

IF @retcode = 1 RETURN

  

See Also
sysservers sp_link_publication
sp_addsubscription sp_addpullsubscription
Triggers sp_check_for_sync_trigger

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.