Aracılığıyla paylaş


Çoğaltma Betiklerini Güncelleme (Çoğaltma Transact-SQL Programlama)

Şunlar için geçerlidir:SQL ServerAzure SQL Yönetilen Örneği

Transact-SQL betik dosyaları, bir çoğaltma topolojisini program aracılığıyla yapılandırmak için kullanılabilir. Daha fazla bilgi için bkz: Çoğaltma Sistemi Saklı Yordam Kavramları.

Önemli

Sysadmin rolünün üyeleri tarafından yürütülen betikleri yükseltmeniz gerekmese de, mevcut betikleri bu konuda açıklandığı gibi değiştirmenizi öneririz. Çoğaltma Aracısı Güvenlik Modeli konusunun "Aracıların Gerektirdiği İzinler" bölümünde açıklandığı gibi her çoğaltma aracısı için en düşük izinlere sahip bir hesap belirtin.

Çoğaltma aracısı işlerinin yürütüldiği Microsoft Windows hesaplarını açıkça belirtmenize izin vererek izinler üzerinde daha fazla denetime olanak tanıyan bu güvenlik geliştirmeleri, mevcut betiklerde aşağıdaki saklı yordamları etkiler:

  • sp_addpublication_snapshot:

    Snapshot Aracısının Dağıtımcıda çalıştığı işi oluşturmak için @job_login'u yürütürken @job_password ve olarak Windows kimlik bilgilerini sağlamalısınız.

  • sp_addpushsubscription_agent:

    Şimdi açıkça bir iş eklemek ve Dağıtım Aracısı işinin Dağıtımcıda çalıştığı Windows kimlik bilgilerini ( ve @job_login) sağlamak için @job_password yürütmeniz gerekir. SQL Server'ın SQL Server 2005 (9.x) öncesi sürümlerinde bu, bir gönderme aboneliği oluşturulduğunda otomatik olarak gerçekleştirilir.

  • sp_addmergepushsubscription_agent:

    Şimdi açıkça bir iş eklemek ve Dağıtımcıda Birleştirme Aracısı işinin çalıştığı Windows kimlik bilgilerini ( ve @job_login) sağlamak için @job_password yürütmeniz gerekir. SQL Server'ın SQL Server 2005 (9.x) öncesi sürümlerinde bu, bir gönderme aboneliği oluşturulduğunda otomatik olarak gerçekleştirilir.

  • sp_addpullsubscription_agent:

    Şimdi, Dağıtım Aracısı'nın Abonede çalıştığı işi oluşturmak için @job_login yürütürken, @job_password ve olarak Windows kimlik bilgilerini sağlamanız gerekir.

  • sp_addmergepullsubscription_agent:

    Şimdi, Birleştirme Aracısının Abonede çalıştığı işi oluşturmak için @job_login yürütürken @job_password ve olarak Windows kimlik bilgilerini sağlamanız gerekir.

  • sp_addlogreader_agent:

    Şimdi görevi elle eklemek ve Log Okuyucu Aracısı'nın Dağıtıcıda çalıştığı Windows kimlik bilgilerini sağlamak için sp_addlogreader_agent (Transact-SQL) yürütün. SQL Server'ın SQL Server 2005 (9.x) öncesi sürümlerinde, işlem yayını oluşturulduğunda bu otomatik olarak gerçekleştirilir.

  • sp_addqreader_agent:

    Şimdi sp_addqreader_agent (Transact-SQL) komutunu çalıştırarak işi el ile eklemeli ve Kuyruk Okuyucu Aracısı'nın Dağıtımcı'da çalıştığı Windows kimlik bilgilerini sağlamalısınız. SQL Server'ın SQL Server 2005 (9.x) öncesi sürümlerinde bu, kuyruğa alınmış güncelleştirmeyi destekleyen bir işlem yayını oluşturulduğunda otomatik olarak gerçekleştirilir.

SQL Server 2005'te (9.x) tanıtılan güvenlik modelinde, çoğaltma aracıları her zaman @job_name ve @job_password içinde sağlanan kimlik bilgilerini kullanarak Windows Kimlik Doğrulaması ile SQL Server'ın yerel örneğine bağlantı kurar. Çoğaltma aracısı işleri çalıştırılırken kullanılan Windows hesaplarının gereksinimleri hakkında bilgi için bkz . Çoğaltma Aracısı Güvenlik Modeli.

Önemli

Mümkün olduğunda, kullanıcılardan çalışma zamanında güvenlik kimlik bilgilerini girmelerini iste. Kimlik bilgilerini bir betik dosyasında depolarsanız, dosyanın güvenliğinin sağlandığından emin olun.

Anlık görüntü veya işlem yayını yapılandıran betikleri yükseltmek için

  1. Var olan betikte, yayın veritabanındaki Publisher'da sp_addlogreader_agent (Transact-SQL)'i çalıştırdıktan sonra, sp_addpublication (Transact-SQL)'yi yürütün. Günlük Okuyucu Aracısı'nın @job_name ve @job_password için çalıştığı Windows kimlik bilgilerini belirtin. Aracı, Publisher'a bağlanırken SQL Server Kimlik Doğrulaması kullanacaksa, için @publisher_security_mode değerini ve @publisher_login ile @publisher_password için SQL Server oturum açma bilgilerini de belirtmeniz gerekir. Bu, yayın veritabanı için bir Günlük Okuyucu Aracısı görevi oluşturur.

    Uyarı

    Bu adım yalnızca işlem yayınları içindir ve anlık görüntü yayınları için gerekli değildir.

  2. (İsteğe bağlı) Dağıtım veritabanındaki Dağıtımcıda sp_addqreader_agent (Transact-SQL) çalıştırmadan önce sp_addpublication (Transact-SQL) çalıştırın. Kuyruk Okuyucu Aracısı'nın @job_name ve @job_password için çalıştırıldığı Windows kimlik bilgilerini belirtin. Bu, Dağıtımcı için bir Kuyruk Okuyucu Aracısı işi oluşturur.

    Uyarı

    Bu adım yalnızca kuyruğa alınmış güncelleştirme abonelerini destekleyen işlem yayınları için gereklidir.

  3. (İsteğe bağlı) Yeni çoğaltma işlevleri uygulayan parametreler için varsayılan olmayan değerleri ayarlamak üzere sp_addpublication (Transact-SQL) yürütmesini güncelleştirin.

  4. sp_addpublication (Transact-SQL) sonrası, yayın veritabanındaki Publisher'da sp_addpublication_snapshot (Transact-SQL) yürütün. @publication belirtin ve Snapshot Aracısının @job_name ve @job_password için çalıştığı Windows kimlik bilgilerini girin. Aracı, Publisher'a bağlanırken SQL Server Kimlik Doğrulaması kullanacaksa, için @publisher_security_mode değerini ve @publisher_login ile @publisher_password için SQL Server oturum açma bilgilerini de belirtmeniz gerekir. Bu, yayın için bir Anlık Görüntü Aracısı işi oluşturur.

  5. (İsteğe bağlı) Yeni çoğaltma işlevleri uygulayan parametreler için varsayılan olmayan değerleri ayarlamak üzere sp_addarticle (Transact-SQL) yürütmesini güncelleştirin.

Anlık görüntüye veya işlem yayınına abonelik ekleyen betiklerin yükseltilmesi için

  1. Aboneliği oluşturan saklı yordamı yürüttkten sonra, aboneliği eşitlemek için bir Dağıtım Aracısı işi oluşturan saklı yordamı yürüttüğünden emin olun. Kullandığınız saklı yordam, aboneliğin türüne bağlıdır.

Birleştirme yayını yapılandıran betikleri yükseltmek için

  1. (İsteğe bağlı) Mevcut betikte, yeni çoğaltma işlevleri uygulayan parametreler için varsayılan olmayan değerleri ayarlamak üzere sp_addmergepublication (Transact-SQL) yürütmesini güncelleştirin.

  2. sp_addmergepublication (Transact-SQL) ardından yayın veritabanındaki Publisher üzerinde sp_addpublication_snapshot (Transact-SQL) yürütün. @publication belirtin ve Snapshot Aracısının @job_name ve @job_password için çalıştığı Windows kimlik bilgilerini girin. Aracı, Publisher'a bağlanırken SQL Server Kimlik Doğrulaması kullanacaksa, için @publisher_security_mode değerini ve @publisher_login ile @publisher_password için SQL Server oturum açma bilgilerini de belirtmeniz gerekir. Bu, yayın için bir Anlık Görüntü Aracısı işi oluşturur.

  3. (İsteğe bağlı) yeni çoğaltma işlevleri uygulayan parametreler için varsayılan olmayan değerleri ayarlamak üzere sp_addmergearticle (Transact-SQL) yürütmesini güncelleştirin.

Birleştirme yayınına abonelik ekleyen betikleri yükseltmek için

  1. Aboneliği oluşturan saklı yordamı yürüttkten sonra, aboneliği eşitlemek için bir Birleştirme Aracısı işi oluşturan saklı yordamı yürüttüğünden emin olun. Kullandığınız saklı yordam, aboneliğin türüne bağlıdır.

Örnekler

A. SQL Server 2000 komut dosyası ile işlemsel yayın oluşturma

Aşağıda, Product tablosu için transaksiyonel yayın oluşturan bir SQL Server 2000 (8.x) betiği örneği verilmiştir. Bu yayın, sıraya alınmış güncellemeyi yedekleme olarak kullanarak anında güncellemeyi destekler. Okunabilirlik için varsayılan parametreler kaldırıldı.

USE [Northwind]
GO

DECLARE @publication AS sysname
DECLARE @publicationDB AS sysname
DECLARE @article AS sysname
SET @publication = N'NwdProductTran'
SET @publicationDB = N'Northwind'
SET @article = N'Products'

-- Enable the replication database.
EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'publish', 
    @value = N'true'

-- Add the transactional publication.
EXEC sp_addpublication 
    @publication = @publication, 
    @sync_method = N'native', 
    @status = N'active', 
    @repl_freq = N'continuous', 
    @description = N'Transactional publication of Northwind.', 
    @allow_push = N'true', 
    @allow_pull = N'true', 
    @allow_sync_tran = N'true', 
    @autogen_sync_procs = N'true', 
    @allow_queued_tran = N'true'

-- Add a snapshot job.
EXEC sp_addpublication_snapshot 
    @publication = @publication

-- Add the transactional articles.
EXEC sp_addarticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @destination_table = @article, 
    @type = N'logbased', 
    @schema_option = 0x00000000000080F3, 
    @ins_cmd = N'CALL sp_MSins_Products', 
    @del_cmd = N'XCALL sp_MSdel_Products', 
    @upd_cmd = N'XCALL sp_MSupd_Products', 
    @auto_identity_range = N'false'
GO

B. SQL Server 2005 ve sonraki sürümler için bir işlem yayını oluşturma betiği

Aşağıda, SQL Server 2005 (9.x) ve sonraki sürümlerde başarıyla çalıştırılacak bir işlem yayını oluşturan önceki betiği yükseltme örneği verilmiştir. Bu yayın, sıraya alınmış güncellemeyi yedekleme olarak kullanarak anında güncellemeyi destekler. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- To avoid storing the login and password in the script file, the value 
-- is passed into SQLCMD as a scripting variable. For information about 
-- how to use scripting variables on the command line and in SQL Server
-- Management Studio, see the "Executing Replication Scripts" section in
-- the topic "Programming Replication Using System Stored Procedures".

-- Execute at the Distributor.
USE [distribution]

DECLARE @login AS sysname;
DECLARE @password AS sysname;
-- Specify the Windows account to run the Queue Reader Agent.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- Execute sp_addqreader_agent to create the Queue Reader Agent job. 
EXEC sp_addqreader_agent 
    @job_login = @login, 
    @job_password = @password;
GO

-- Execute at the Publisher.
USE [Northwind]
GO

DECLARE @publication AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @article AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran';
SET @publicationDB = N'Northwind';
SET @article = N'Products';
-- Specify the Windows account to run the Log Reader and Snapshot Agents.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- Enable the replication database.
EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'publish', 
    @value = N'true';

-- Execute sp_addlogreader_agent to create the agent job. 
EXEC sp_addlogreader_agent 
    @job_login = @login, 
    @job_password = @password, 
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Add the transactional publication.
EXEC sp_addpublication 
    @publication = @publication, 
    @sync_method = N'native', 
    @repl_freq = N'continuous', 
    @status = N'active',
    @description = N'Transactional publication of Northwind.', 
    @allow_push = N'true', 
    @allow_pull = N'true', 
    @allow_sync_tran = N'true', 
    @autogen_sync_procs = N'true', 
    @allow_queued_tran = N'true',
    @replicate_ddl = 1,
    @enabled_for_p2p = N'false';

-- Create a new snapshot job for the publication, using a default schedule.
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Add a transactional article.
EXEC sp_addarticle 
  @publication = @publication, 
  @article = @article, 
  @source_owner = N'dbo', 
  @source_object = @article, 
  @destination_table = @article, 
  @type = N'logbased', 
  @schema_option = 0x00000000000080F3, 
  @ins_cmd = N'CALL sp_MSins_Products', 
  @del_cmd = N'XCALL sp_MSdel_Products', 
  @upd_cmd = N'XCALL sp_MSupd_Products', 
  @auto_identity_range = N'false',
  @identityrangemanagementoption = N'manual',
  @fire_triggers_on_snapshot = N'false';
GO

C. Birleştirme yayını oluşturmak için SQL Server 2000 betiği

Aşağıda, Müşteriler tablosu için birleştirme yayını oluşturan bir SQL Server 2000 (8.x) betiği örneği verilmiştir. Okunabilirlik için varsayılan parametreler kaldırıldı.

-- Enable the replication database.
USE [Northwind]
GO

DECLARE @publicationDB AS sysname
DECLARE @publication AS sysname
DECLARE @article AS sysname
SET @publicationDB = N'Northwind' 
SET @publication = N'NwdCustomersMerge' 
SET @article = N'Customers' 

EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'merge publish', 
    @value = N'true'

-- Add the merge publication.
EXEC sp_addmergepublication 
    @publication = @publication, 
    @description = N'Merge publication of Northwind.', 
    @retention = 14, 
    @sync_mode = N'native', 
    @centralized_conflicts = N'true', 
    @dynamic_filters = N'false', 
    @keep_partition_changes = N'false'
 
EXEC sp_addpublication_snapshot 
    @publication = @publication

-- Add the merge articles.
EXEC sp_addmergearticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @type = N'table', 
    @description = null, 
    @column_tracking = N'true', 
    @schema_option = 0x000000000000CFF1
 GO

D. Birleştirme yayını oluşturmak için SQL Server 2005 ve üzeri betik

Aşağıda, SQL Server 2005 (9.x) ve sonraki sürümler için başarıyla çalıştırılacak şekilde yükseltilen bir birleştirme yayını oluşturan önceki betiğin bir örneği verilmiştir. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- To avoid storing the login and password in the script file, the value 
-- is passed into SQLCMD as a scripting variable. For information about 
-- how to use scripting variables on the command line and in SQL Server
-- Management Studio, see the "Executing Replication Scripts" section in
-- the topic "Programming Replication Using System Stored Procedures".

-- Enabling the replication database
-- Enable the replication database.
USE [Northwind]
GO

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @article AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'Northwind';
SET @publication = N'NwdCustomersMerge';
SET @article = N'Customers';
-- Specify the Windows account to run the Snapshot Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'merge publish', 
    @value = N'true';

-- Add the merge publication.
EXEC sp_addmergepublication 
    @publication = @publication, 
    @description = N'Merge publication of Northwind.', 
    @retention = 14, 
    @sync_mode = N'native', 
    @dynamic_filters = N'false', 
    @keep_partition_changes = N'false',
    -- Only set to '90RTM' if all Subscribers are SQL Server 2005.
    @publication_compatibility_level = N'90RTM',
    @replicate_ddl = 1,
    @allow_subscriber_initiated_snapshot = N'true',
    @allow_web_synchronization = N'false',
    @allow_partition_realignment = N'true',
    @retention_period_unit = N'day',
    @automatic_reinitialization_policy = 0,
    @conflict_logging = N'both';
 
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login,
    @job_password = @password;

-- Add the merge article.
EXEC sp_addmergearticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @type = N'table', 
    @description = null, 
    @column_tracking = N'true', 
    @schema_option = 0x0000000000034FD1,
    @partition_options = 0,
    @subscriber_upload_options = 0,
    @identityrangemanagementoption = N'manual',
    @delete_tracking = N'true',
    @compensate_for_errors = N'false',
    @stream_blob_columns = N'true';
GO

E. İşlem yayınına anında iletme aboneliği oluşturmak için SQL Server 2000 betiği

Aşağıda, işlem yayınına anında iletme aboneliği oluşturan bir SQL Server 2000 (8.x) betiği örneği verilmiştir. Okunabilirlik için varsayılan parametreler kaldırıldı.

DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdProductTran' 
SET @subscriber = N'MYSUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
    @subscriber = @subscriber

-- Add a push subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'push'
GO

F. İşlem yayınına anında iletme aboneliği oluşturmak için SQL Server 2005 ve üzeri betiği

Aşağıda, SQL Server 2005 (9.x) ve sonraki sürümlerde başarıyla çalıştırılacak şekilde yükseltilen, işlem yayınına gönderim aboneliği oluşturan önceki betiğin bir örneği verilmiştir. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 
-- Specify the Windows account to run the Distribution Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

-- Add a push subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'push';

-- Add an agent job to synchronize the push subscription.
EXEC sp_addpushsubscription_agent 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @job_login = @login, 
    @job_password = @password;
GO

G. Birleştirme yayınına anında iletme aboneliği oluşturmak için SQL Server 2000 betiği

Aşağıda, birleştirme yayınına push aboneliği oluşturan bir SQL Server 2000 (8.x) betiği örneği verilmiştir. Okunabilirlik için varsayılan parametreler kaldırıldı.

DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'push',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

H. Birleştirme yayınına anında iletme aboneliği oluşturmak için SQL Server 2005 ve üzeri betiği

Aşağıda, SQL Server 2005 (9.x) ve sonraki sürümler için başarıyla çalışacak şekilde güncellenmiş bir birleştirme yayınına push aboneliği oluşturan önceki senaryonun bir örneği verilmiştir. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdCustomersMerge'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 
-- Specify the Windows account to run the Merge Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @subscription_type = N'push';

-- Add an agent job to synchronize the push subscription.
EXEC sp_addmergepushsubscription_agent 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @job_login = @login, 
    @job_password = @password;
GO

Ben. İşlemsel bir yayına çekme aboneliği oluşturmak için SQL Server 2000 betiği

Aşağıda, bir işlem yayınına çekme aboneliği oluşturan SQL Server 2000 (8.x) betiği örneği verilmiştir. Okunabilirlik için varsayılan parametreler kaldırıldı.

DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'push',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

J. SQL Server 2005 ve sonraki sürümler için bir işlem yayınına çekme aboneliği oluşturma betiği

Aşağıda, SQL Server 2005 (9.x) ve sonraki sürümler için başarıyla çalıştırılacak şekilde yükseltilen bir işlem yayınına çekme aboneliği oluşturan önceki betiğin bir örneği verilmiştir. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran'; 
SET @publisher = $(Publisher); 
SET @publicationDB = N'Northwind'; 
-- Specify the Windows account to run the Distribution Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [NorthwindReplica]
EXEC sp_addpullsubscription 
    @publisher = @publisher, 
    @publication = @publication, 
    @publisher_db = @publicationDB,
    @subscription_type = N'pull';

-- Add an agent job to synchronize the pull subscription.
EXEC sp_addpullsubscription_agent 
    @publisher = @publisher, 
    @publisher_db = @publicationDB, 
    @publication = @publication, 
    @distributor = @publisher,
    @job_login = @login,
    @job_password = @password;
GO

-- Execute at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdProductTran'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 

-- Add a pull subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'pull';
GO

K. Birleştirme yayınına veri çekme aboneliği oluşturmak için SQL Server 2000 betiği

Aşağıda, birleştirme yayınına çekme aboneliği oluşturan bir SQL Server 2000 (8.x) betiği örneği verilmiştir. Okunabilirlik için varsayılan parametreler kaldırıldı.

-- Execute at the Subscriber
DECLARE @publication AS sysname
DECLARE @publisher AS sysname
DECLARE @publicationDB AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @publisher = N'PUBSERVER' 
SET @publicationDB = N'Northwind' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica'

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [NorthwindReplica]
EXEC sp_addmergepullsubscription 
    @publisher = @publisher, 
    @publication = @publication, 
    @publisher_db = @publicationDB

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
    @publisher = @publisher, 
    @publisher_db = @publicationDB, 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @distributor = @publisher
GO

-- Execute at the Publisher.
DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'MYSUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a pull subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'pull',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

L. Birleştirme yayınına çekme aboneliği oluşturmak için SQL Server 2005 ve sonrası için betik

Aşağıda, bir birleştirme yayını için çekme aboneliği oluşturan ve SQL Server 2005 (9.x) ve sonraki sürümlerde başarıyla çalışacak şekilde yükseltilmiş olan önceki betiğin bir örneği verilmiştir. Yeni parametreler için varsayılanlar açıkça bildirilmiştir.

Uyarı

Windows kimlik bilgileri çalışma zamanında sqlcmd betik değişkenleri kullanılarak sağlanır.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute at the Subscriber
DECLARE @publication  AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdCustomersMerge'; 
SET @publisher = $(Publisher); 
SET @publicationDB = N'Northwind'; 
-- Specify the Windows account to run the Merge Agent.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [NorthwindReplica]
EXEC sp_addmergepullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication,
  @distributor = @publisher,
  @job_login = @login,
  @job_password = @password;
GO

-- Execute at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdCustomersMerge';
SET @subscriber = $(Subscriber);
SET @subscriptionDB = N'NorthwindReplica';

-- Add a pull subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'pull',
  @subscriber_type = N'local',
  @sync_type = N'automatic';
GO