Home > Articles > Data > SQL Server

  • Print
  • + Share This
Like this article? We recommend

Synchronizing Replicated Code Modules

Non-table articles are synchronized only when the Snapshot agent runs and updates subscriber databases. For this article, I published the stored procedure and UDF that you saw earlier, as well as titleview view included with pubs database.

Immediately after creating the subscription, Enterprise Manager reports that subscription's status is Pending (as shown in the following figure) because the Snapshot agent hasn't taken the snapshot of the articles yet.

Figure 3Figure 3

After you run the Snapshot agent, it creates the scripts for generating the replicated articles on the subscriber. These scripts reside in the snapshot directory you specified during publication setup. (By default, this directory is Program Files\Microsoft SQL Server\MSSQL\REPLDATA\UNC\server_name_publication_name_subscription_name.) After the log reader and distribution agent run, SQL Server will delete the snapshot scripts. After the initial snapshot has been delivered, the Status column will say Active.

Although you can run the Snapshot agent as often as you like, it generates the snapshot of the published articles only if the subscriptions are marked for re-initialization. If the Snapshot agent doesn't find any subscriptions that need to be re-initialized, it simply returns the following message within the replication monitor (as shown in the following figure): "A snapshot was not generated because no subscriptions needed initialization."

Figure 4Figure 4

You might think that if you change the replicated code module's definition that SQL Server would automatically reinitialize the subscriptions, but if you modify the replicated stored procedure and run the Snapshot agent manually, it still reports the same message. Furthermore, if you check the replicated procedure's code on the subscriber, you'll notice that changes haven't been applied.

To reinitialize the subscription, you need to navigate to the publication within Enterprise Manger, right-click the desired subscription, and choose Re-initialize. SQL Server then executes a system stored procedure called sp_reinitsubscription, which in turn calls sp_changesubstatus—this procedure modifies the Status column of the syssubscriptions system table found in the published database. It is the Status column that determines whether the subscription is re-initialized. When you re-initialize the subscription, Enterprise Manager changes the value of the Status column to Pending, just as it appeared during the initial synchronization. Next time the Snapshot agent runs, it will report a message stating that the snapshot of replicated articles has been generated, as shown in the following figure.

Figure 5Figure 5

If you examine the replicated articles, you'll notice that changes have made their way to the subscriber.


You can also re-initialize subscriptions by examining the publication properties, navigating to the Subscriptions tab and choosing Re-initialize.

  • + Share This
  • 🔖 Save To Your Account