Çekme abonelik oluştur
Bu konuyu açıklar nasıl bir çekme abonelik oluşturmak SQL Server 2012kullanarak SQL Server Management Studio, Transact-SQL, ya da Çoğaltma Yönetimi Nesneleri'ni (rmo).
Bu Konuda
Çekme abonelik oluşturmak için kullanma:
SQL Server Management Studio
Transact-SQL
Çoğaltma Yönetimi Nesneleri'ni (rmo)
SQL Server Management Studio Kullanarak
Çekme abonelik yayımcı veya abone Yeni Abonelik Sihirbazı'nı kullanarak oluşturun. İçin sihirbazın sayfalarını izleyin:
Basım ve Yayınevi belirtin.
Çoğaltma aracıları çalıştırılacağı seçin. Çekme abonelik için Seç onun abone (çekme abonelikleri) her aracı çalıştırmak üzerinde Dağıtım Aracısı konumu sayfa veya Birleştirme Aracısı konumu sayfasında, yayının türüne bağlı.
Abone ve abonelik veritabanları belirtin.
Oturum ve parolalar çoğaltma aracıları tarafından yapılan bağlantılar için kullanılan belirtin:
Anlık görüntü ve işlem yayınları abonelikleri için kimlik bilgilerini belirtin Dağıtım Aracısı güvenlik sayfa.
Yayınlar birleştirme abonelikleri için kimlik bilgilerini belirtin Birleştirme Aracısı güvenlik sayfa.
Her Aracısı tarafından gerekli izinler hakkında daha fazla bilgi için bkz: Çoğaltma aracısı güvenlik modeli.
Eşitleme zamanlaması ve ne zaman abone başlatılması belirtin.
Birleştirme yayımları için ek seçenekleri belirleyin: abonelik türü; parametreli filtre uygulamak için değerleri; ve bilgi için yayının Web eşitleme etkinse, https üzerinden eşitleme.
Abonelikleri güncelleştirmek izin işlem yayınlar için ek seçenekleri belirleyin: aboneleri veya tamamlama değişiklikleri yayımcı hemen sıraya; yazın Abone için yayımcı bağlanmak için kullanılan kimlik bilgileri.
Abonelik isteğe bağlı olarak komut dosyası.
Yayımcı bir çekme abonelik oluşturmak için
Yayımcı bağlanmak Microsoft SQL Server Management Studiove sonra sunucu düğümünü genişletin.
Genişletme çoğaltma klasörünü ve ardından Yerel yayınları klasörü.
Bir veya daha fazla abonelikleri oluşturma ve tıklatın istediğiniz yayını sağ tıklatın Yeni abonelikleri.
Yeni Abonelik Sihirbazı sayfalarında tamamlayın.
Abonenin çekme abonelik oluşturmak için
Abone bağlanmak SQL Server Management Studiove sonra sunucu düğümünü genişletin.
Genişletme çoğaltma ağıl.
Sağ Yerel Abonelikleri klasörünü ve sonra Yeni abonelikleri.
Tarih yayın Yeni Abonelik Sihirbazı seçin sayfasında <SQL Server yayımcı bulmak > veya <Oracle yayımcı bulmak > dan Publisher açılan liste.
Yayımcı bağlanma sunucuya Bağlan iletişim kutusu.
Yayını seçin yayın sayfa.
Yeni Abonelik Sihirbazı sayfalarında tamamlayın.
[Top]
Transact-SQL'i Kullanma
Çekme abonelikleri çoğaltma depolanmış yordamları kullanarak programsal oluşturulabilir. Kullanılan saklı yordamlar abonelik ait olduğu yayın türüne bağlıdır.
Anlık görüntü veya işlem yayın için çekme abonelik oluşturmak için
Yayımcı tarafında yayını yürüterek çekme abonelikleri desteklediğini doğrulayın yürütme eşdeğerdirsp_helppublication (Transact-sql).
Eğer değeri allow_pull sonuç kümesi olan 1, sonra yayını çekme abonelikleri destekler.
Eğer değeri allow_pull olan 0, yürütme yürütmesp_changepublication (Transact-sql), belirtme allow_pull için @ özellik ve trueiçin @ değeri.
Abone tarafında idam yürütme eşdeğerdirsp_addpullsubscription (Transact-sql). Belirtmek @ publisher ve @ yayın. Abonelikleri güncelleştirme hakkında daha fazla bilgi için bkz: İşlem yayınına güncelleştirilebilir bir abonelik oluştur.
Abone tarafında idam yürütme eşdeğerdirsp_addpullsubscription_agent (Transact-sql). Aşağıdakileri belirtin:
@ Publisher, @ publisher_db, ve @ yayın parametreleri.
MicrosoftAbone adresindeki dağıtım aracı için çalıştığı Windows kimlik bilgileri @ job_login ve @ job_password.
[!NOT]
Her zaman Windows tümleşik kimlik doğrulaması kullanılarak yapılan bağlantılar tarafından belirtilen Windows kimlik bilgilerini kullanmak @ job_login ve @ job_password. Dağıtım aracı her zaman Windows tümleşik kimlik doğrulaması kullanarak abone yerel bağlantı yapar. Varsayılan olarak, Windows tümleşik kimlik doğrulaması Dağıtımcı olarak aracı bağlanır.
(İsteğe bağlı) Değeri 0 için @ distributor_security_mode ve Microsoft SQL Servergiriş bilgilerini @ distributor_login ve distributor_password @, kullanmanız gerekiyorsa SQL ServerDağıtımcı olarak bağlanırken kimlik.
Bu abonelik için dağıtım aracısını iş için zamanlama. Daha fazla bilgi için, bkz. Eşitleme çizelgelerini belirleme.
Yayımcı tarafında idam sp_addsubscription (Transact-sql)Çekme abonelik kayıt için. Belirtmek @ yayın, @ abone, ve @ destination_db. Değeri belirtmeniz Tanıtım için @ subscription_type.
Çekme abonelik için birleştirme yayını oluşturmak için
Yayımcı tarafında yayını yürüterek çekme abonelikleri desteklediğini doğrulayın eşdeğerdirsp_helpmergepublication (Transact-sql).
Eğer değeri allow_pull sonuç kümesi olan 1, sonra yayını çekme abonelikleri destekler.
Eğer değeri allow_pull olan 0, yürütme yürütmesp_changemergepublication (Transact-sql), belirtme allow_pull için @ özellik ve trueiçin @ değeri.
Abone tarafında idam sp_addmergepullsubscription (Transact-sql). Belirtmek @ publisher, @ publisher_db, @ yayınve aşağıdaki parametreleri:
@ subscriber_type – belirtmek Yerel istemci abonelik ve Genel sunucu abonelik.
@ subscription_priority -abonelik için bir öncelik belirlemek (0.00 için 99.99). Yalnızca bu sunucu abonelik için gerekli.
Daha fazla bilgi için, bkz. Gelişmiş birleştirme çoğaltma çakışma algılaması ve Çözümlemesi.
Abone tarafında idam sp_addmergepullsubscription_agent (Transact-sql). Aşağıdaki parametreleri belirtme:
@ publisher, @ publisher_db, ve @ yayın.
Birleştirme Aracısı abone çalıştığı için Windows kimlik bilgileri @ job_login ve @ job_password.
[!NOT]
Her zaman Windows tümleşik kimlik doğrulaması kullanılarak yapılan bağlantılar tarafından belirtilen Windows kimlik bilgilerini kullanmak @ job_login ve @ job_password. Birleştirme aracı her zaman Windows tümleşik kimlik doğrulaması kullanarak abone yerel bağlantı yapar. Varsayılan olarak, tümleşik Windows kimlik doğrulaması kullanarak Publisher ve dağıtımcı Aracısı bağlanır.
(İsteğe bağlı) Değeri 0 için @ distributor_security_mode ve SQL Serveriçin oturum açma bilgilerini @ distributor_login ve distributor_password @, kullanmanız gerekiyorsa SQL ServerDağıtımcı olarak bağlanırken kimlik.
(İsteğe bağlı) Değeri 0 için @ publisher_security_mode ve SQL Serveriçin oturum açma bilgilerini @ publisher_login ve publisher_password @, kullanmanız gerekiyorsa SQL Serveriçin yayımcı bağlanırken kimlik.
Bu abonelik için Birleştirme Aracısı iş için zamanlama. Daha fazla bilgi için, bkz. İşlem yayınına güncelleştirilebilir bir abonelik oluştur.
Yayımcı tarafında idam sp_addmergesubscription (Transact-sql). Belirtmek @ yayın, @ abone, @ subscriber_dbbir Tanıtım için @ subscription_type. Bu çekme abonelik kaydeder.
Örnekler (Transact-SQL)
Aşağıdaki örnek, bir çekme abonelik işlem yayınına oluşturur. İlk toplu abone adresindeki yürütülür ve ikinci toplu yayımcı adresindeki yürütülür. Oturum açma ve parola değerleri sqlcmd komut dosyası değişkenleri kullanarak çalışma zamanında 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 this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2012';
-- At the subscription database, create a pull subscription
-- to a transactional publication.
USE [AdventureWorks2012Replica]
EXEC sp_addpullsubscription
@publisher = @publisher,
@publication = @publication,
@publisher_db = @publicationDB;
-- 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
-- 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 this batch at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @subscriber = $(SubServer);
SET @subscriptionDB = N'AdventureWorks2012Replica';
-- At the Publisher, register the subscription, using the defaults.
EXEC sp_addsubscription
@publication = @publication,
@subscriber = @subscriber,
@destination_db = @subscriptionDB,
@subscription_type = N'pull',
@status = N'subscribed';
GO
Aşağıdaki örnek, bir çekme abonelik birleştirme yayınına oluşturur. İlk toplu abone adresindeki yürütülür ve ikinci toplu yayımcı adresindeki yürütülür. Oturum açma ve parola değerleri kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.
-- 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 this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @hostname AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2012';
SET @hostname = N'adventure-works\david8';
-- At the subscription database, create a pull subscription
-- to a merge publication.
USE [AdventureWorks2012Replica]
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),
@hostname = @hostname;
GO
-- Execute this batch at the Publisher.
DECLARE @myMergePub AS sysname;
DECLARE @mySub AS sysname;
DECLARE @mySubDB AS sysname;
SET @myMergePub = N'AdvWorksSalesOrdersMerge';
SET @mySub = N'MYSUBSERVER';
SET @mySubDB = N'AdventureWorks2012Replica';
-- At the Publisher, register the subscription, using the defaults.
USE [AdventureWorks2012]
EXEC sp_addmergesubscription @publication = @myMergePub,
@subscriber = @mySub, @subscriber_db = @mySubDB,
@subscription_type = N'pull';
GO
[Top]
Çoğaltma Yönetimi Nesneleri'ni (rmo) kullanarak
Çekme abonelik oluşturmak için kullanılan rmo sınıfları abonelik ait olduğu yayın türüne bağlıdır.
Anlık görüntü veya işlem yayın için çekme abonelik oluşturmak için
Publisher ve abone bağlantıları kullanarak oluşturma ServerConnectionsınıf
Örneğini TransPublicationsınıfı kullanarak Publisher bağlantı adım 1. Specify Name, DatabaseName and ConnectionContext.
Arama LoadPropertiesyöntemi. Bu yöntem ise false, adım 2'de belirtilen özellikleri yanlış veya Yayını sunucuda yok.
Bit düzeyinde mantıksal ve gerçekleştirme ( & Visual C# ve AndVisual Basic) arasında Attributesözelliği ve AllowPull. Sonuç ise NoneSystem, Attributesiçin bit düzeyinde mantıksal or sonucu ( |Visual C# ve OrVisual Basic) arasında Attributesve AllowPull. Sonra arama CommitPropertyChangesçekme abonelikleri etkinleştirmek için.
Abonelik veritabanı yoksa, bunu kullanarak oluşturmak Databasesınıf Daha fazla bilgi için, bkz. Oluşturma, değiştirme ve veritabanları kaldırma.
Örneğini TransPullSubscriptionsınıf
Aşağıdaki abonelik özelliklerini ayarlayın:
ServerConnectionİçin adım 1'de oluşturulan abone ConnectionContext.
Abonelik veritabanı adı DatabaseName.
Yayımcı için adı PublisherName.
Yayını veritabanı için adı PublicationDBName.
Yayın adı PublicationName.
LoginVe Passwordya SecurePasswordalanlar SynchronizationAgentProcessSecurityiçin kimlik bilgileri sağlamak için MicrosoftDağıtım aracı çalıştığı abone adresindeki Windows hesabı. Bu hesap, yerel bağlantılar için abone olun ve Windows kimlik doğrulaması kullanarak uzak bağlantıları sağlamak için kullanılır.
[!NOT]
Ayar SynchronizationAgentProcessSecuritybir üyesi tarafından abonelik oluşturulduğunda gerekli değildir sysadminsabit sunucu rolü, ancak önerilir. Bu durumda, aracı SQL Server Agent hesabı taklit. Daha fazla bilgi için, bkz. Çoğaltma aracısı güvenlik modeli.
(İsteğe bağlı) Değeri trueiçin CreateSyncAgentByDefaultAbonelik eşitlemek için kullanılan bir Aracısı işi oluşturmak için. If you specify falseAbonelik yalnızca program aracılığıyla senkronize edilebilir ve ek özelliklerini belirtmeniz gerekir (varsayılan), TransSynchronizationAgentBu nesneden eriştiğinizde SynchronizationAgentözellik. Daha fazla bilgi için, bkz. Çekme abonelik Eşitle.
[!NOT]
SQL Server Agent her sürümünde kullanılabilir değil Microsoft SQL Server. Sürümü tarafından desteklenen özellikleri listesi için SQL Serverbakın SQL Server 2012 Sürümleri Tarafından Desteklenen Özellikler. Ne zaman sizin belirlediğiniz değeri trueExpress aboneleri için Aracısı işi oluşturulmaz. Ancak, önemli abonelik ile ilişkili meta abone depolanır.
(İsteğe bağlı) Set SqlStandardLoginve SqlStandardPasswordya SecureSqlStandardPasswordalanlar DistributorSecuritySQL Server kimlik doğrulaması Dağıtımcı olarak bağlanmak için kullanırken.
Arama Createyöntemi.
Örneğini kullanarak TransPublicationAdım 2, çağrı sınıfı MakePullSubscriptionWellKnownyayımcı ile çekme abonelik kayıt yöntemi. Bu kayıt varsa, bir özel durum oluşur.
Çekme abonelik için birleştirme yayını oluşturmak için
Publisher ve abone bağlantıları kullanarak oluşturma ServerConnectionsınıf
Örneğini MergePublicationsınıfı kullanarak Publisher bağlantı adım 1. Specify Name, DatabaseName, and ConnectionContext.
Arama LoadPropertiesyöntemi. Bu yöntem ise false, adım 2'de belirtilen özellikleri yanlış veya Yayını sunucuda yok.
Bit düzeyinde mantıksal ve gerçekleştirme ( & Visual C# ve AndVisual Basic) arasında Attributesözelliği ve AllowPull. Sonuç ise NoneSystem, Attributesiçin bit düzeyinde mantıksal or sonucu ( |Visual C# ve OrVisual Basic) arasında Attributesve AllowPull. Sonra arama CommitPropertyChangesçekme abonelikleri etkinleştirmek için.
Abonelik veritabanı yoksa, bunu kullanarak oluşturmak Databasesınıf Daha fazla bilgi için, bkz. Oluşturma, değiştirme ve veritabanları kaldırma.
Örneğini MergePullSubscriptionsınıf
Aşağıdaki abonelik özelliklerini ayarlayın:
ServerConnectionİçin adım 1'de oluşturulan abone ConnectionContext.
Abonelik veritabanı adı DatabaseName.
Yayımcı için adı PublisherName.
Yayını veritabanı için adı PublicationDBName.
Yayın adı PublicationName.
LoginVe Passwordya SecurePasswordalanlar SynchronizationAgentProcessSecurityiçin kimlik bilgileri sağlamak için MicrosoftBirleştirme Aracısı çalıştığı abone adresindeki Windows hesabı. Bu hesap, yerel bağlantılar için abone olun ve Windows kimlik doğrulaması kullanarak uzak bağlantıları sağlamak için kullanılır.
[!NOT]
Ayar SynchronizationAgentProcessSecuritybir üyesi tarafından abonelik oluşturulduğunda gerekli değildir sysadminsabit sunucu rolü, ancak önerilir. Bu durumda, aracı SQL Server Agent hesabı taklit. Daha fazla bilgi için, bkz. Çoğaltma aracısı güvenlik modeli.
(İsteğe bağlı) Değeri trueiçin CreateSyncAgentByDefaultAbonelik eşitlemek için kullanılan bir Aracısı işi oluşturmak için. If you specify falseAbonelik yalnızca program aracılığıyla senkronize edilebilir ve ek özelliklerini belirtmeniz gerekir (varsayılan), MergeSynchronizationAgentBu nesneden eriştiğinizde SynchronizationAgentözellik. Daha fazla bilgi için, bkz. Çekme abonelik Eşitle.
(İsteğe bağlı) Set SqlStandardLoginve SqlStandardPasswordya SecureSqlStandardPasswordalanlar DistributorSecuritySQL Server kimlik doğrulaması Dağıtımcı olarak bağlanmak için kullanırken.
(İsteğe bağlı) Set SqlStandardLoginve SqlStandardPasswordya SecureSqlStandardPasswordalanlar PublisherSecurityiçin yayımcı bağlanmak için SQL Server kimlik doğrulaması kullanırken.
Arama Createyöntemi.
Örneğini kullanarak MergePublicationAdım 2, çağrı sınıfı MakePullSubscriptionWellKnownyayımcı ile çekme abonelik kayıt yöntemi. Bu kayıt varsa, bir özel durum oluşur.
Örnek (rmo)
Bu örnek işlem yayınına çekme abonelik oluşturur. MicrosoftDağıtım Aracısı işi oluşturmak için kullanılan Windows hesabının kimlik bilgileri geçti süresinde.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksProductTran";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);
// Create the objects that we need.
TransPublication publication;
TransPullSubscription subscription;
try
{
// Connect to the Publisher and Subscriber.
subscriberConn.Connect();
publisherConn.Connect();
// Ensure that the publication exists and that
// it supports pull subscriptions.
publication = new TransPublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = publisherConn;
if (publication.IsExistingObject)
{
if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPull;
}
// Define the pull subscription.
subscription = new TransPullSubscription();
subscription.ConnectionContext = subscriberConn;
subscription.PublisherName = publisherName;
subscription.PublicationName = publicationName;
subscription.PublicationDBName = publicationDbName;
subscription.DatabaseName = subscriptionDbName;
// Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
subscription.SynchronizationAgentProcessSecurity.Password = winPassword;
// Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = true;
// By default, subscriptions to transactional publications are synchronized
// continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand;
// Create the pull subscription at the Subscriber.
subscription.Create();
Boolean registered = false;
// Verify that the subscription is not already registered.
foreach (TransSubscription existing
in publication.EnumSubscriptions())
{
if (existing.SubscriberName == subscriberName
&& existing.SubscriptionDBName == subscriptionDbName)
{
registered = true;
}
}
if (!registered)
{
// Register the subscription with the Publisher.
publication.MakePullSubscriptionWellKnown(
subscriberName, subscriptionDbName,
SubscriptionSyncType.Automatic,
TransSubscriberType.ReadOnly);
}
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
subscriberConn.Disconnect();
publisherConn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksProductTran"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As TransPublication
Dim subscription As TransPullSubscription
Try
' Connect to the Publisher and Subscriber.
subscriberConn.Connect()
publisherConn.Connect()
' Ensure that the publication exists and that
' it supports pull subscriptions.
publication = New TransPublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = publisherConn
If publication.IsExistingObject Then
If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPull
End If
' Define the pull subscription.
subscription = New TransPullSubscription()
subscription.ConnectionContext = subscriberConn
subscription.PublisherName = publisherName
subscription.PublicationName = publicationName
subscription.PublicationDBName = publicationDbName
subscription.DatabaseName = subscriptionDbName
subscription.Description = "Pull subscription to " + publicationDbName _
+ " on " + subscriberName + "."
' Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin
subscription.SynchronizationAgentProcessSecurity.Password = winPassword
' Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = True
' By default, subscriptions to transactional publications are synchronized
' continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand
' Create the pull subscription at the Subscriber.
subscription.Create()
Dim registered As Boolean = False
' Verify that the subscription is not already registered.
For Each existing As TransSubscription In publication.EnumSubscriptions()
If existing.SubscriberName = subscriberName And _
existing.SubscriptionDBName = subscriptionDbName Then
registered = True
End If
Next existing
If Not registered Then
' Register the subscription with the Publisher.
publication.MakePullSubscriptionWellKnown( _
subscriberName, subscriptionDbName, _
SubscriptionSyncType.Automatic, _
TransSubscriberType.ReadOnly)
End If
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
subscriberConn.Disconnect()
publisherConn.Disconnect()
End Try
Bu örnek, bir çekme abonelik birleştirme yayınına oluşturur. Birleştirme Aracısı işi oluşturmak için kullanılan Windows hesabının kimlik bilgileri, çalışma anında iletilir.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";
//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);
// Create the objects that we need.
MergePublication publication;
MergePullSubscription subscription;
try
{
// Connect to the Subscriber.
subscriberConn.Connect();
// Ensure that the publication exists and that
// it supports pull subscriptions.
publication = new MergePublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = publisherConn;
if (publication.LoadProperties())
{
if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPull;
}
// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = subscriberConn;
subscription.PublisherName = publisherName;
subscription.PublicationName = publicationName;
subscription.PublicationDBName = publicationDbName;
subscription.DatabaseName = subscriptionDbName;
subscription.HostName = hostname;
// Specify the Windows login credentials for the Merge Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
subscription.SynchronizationAgentProcessSecurity.Password = winPassword;
// Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = true;
// Create the pull subscription at the Subscriber.
subscription.Create();
Boolean registered = false;
// Verify that the subscription is not already registered.
foreach (MergeSubscription existing
in publication.EnumSubscriptions())
{
if (existing.SubscriberName == subscriberName
&& existing.SubscriptionDBName == subscriptionDbName
&& existing.SubscriptionType == SubscriptionOption.Pull)
{
registered = true;
}
}
if (!registered)
{
// Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown(
subscriberName, subscriptionDbName,
SubscriptionSyncType.Automatic,
MergeSubscriberType.Local, 0);
}
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
subscriberConn.Disconnect();
publisherConn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"
'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergePullSubscription
Try
' Connect to the Subscriber.
subscriberConn.Connect()
' Ensure that the publication exists and that
' it supports pull subscriptions.
publication = New MergePublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = publisherConn
If publication.LoadProperties() Then
If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPull
End If
' Define the pull subscription.
subscription = New MergePullSubscription()
subscription.ConnectionContext = subscriberConn
subscription.PublisherName = publisherName
subscription.PublicationName = publicationName
subscription.PublicationDBName = publicationDbName
subscription.DatabaseName = subscriptionDbName
subscription.HostName = hostname
' Specify the Windows login credentials for the Merge Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin
subscription.SynchronizationAgentProcessSecurity.Password = winPassword
' Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = True
' Create the pull subscription at the Subscriber.
subscription.Create()
Dim registered As Boolean = False
' Verify that the subscription is not already registered.
For Each existing As MergeSubscription In _
publication.EnumSubscriptions()
If existing.SubscriberName = subscriberName Then
registered = True
End If
Next
If Not registered Then
' Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown( _
subscriberName, subscriptionDbName, _
SubscriptionSyncType.Automatic, _
MergeSubscriberType.Local, 0)
End If
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
subscriberConn.Disconnect()
publisherConn.Disconnect()
End Try
Bu örnek, bir ilişkili Aracısı iş abonelik ve meta verilerde oluşturmadan bir çekme abonelik birleştirme yayınına oluşturur MSsubscription_properties. Birleştirme Aracısı işi oluşturmak için kullanılan Windows hesabının kimlik bilgileri, çalışma anında iletilir.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);
// Create the objects that we need.
MergePublication publication;
MergePullSubscription subscription;
try
{
// Connect to the Subscriber.
subscriberConn.Connect();
// Ensure that the publication exists and that
// it supports pull subscriptions.
publication = new MergePublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = publisherConn;
if (publication.LoadProperties())
{
if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPull;
}
// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = subscriberConn;
subscription.PublisherName = publisherName;
subscription.PublicationName = publicationName;
subscription.PublicationDBName = publicationDbName;
subscription.DatabaseName = subscriptionDbName;
// Specify that an agent job not be created for this subscription. The
// subscription can only be synchronized by running the Merge Agent directly.
// Subscripition metadata stored in MSsubscription_properties will not
// be available and must be specified at run time.
subscription.CreateSyncAgentByDefault = false;
// Create the pull subscription at the Subscriber.
subscription.Create();
Boolean registered = false;
// Verify that the subscription is not already registered.
foreach (MergeSubscription existing
in publication.EnumSubscriptions())
{
if (existing.SubscriberName == subscriberName
&& existing.SubscriptionDBName == subscriptionDbName
&& existing.SubscriptionType == SubscriptionOption.Pull)
{
registered = true;
}
}
if (!registered)
{
// Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown(
subscriberName, subscriptionDbName,
SubscriptionSyncType.Automatic,
MergeSubscriberType.Local, 0);
}
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
subscriberConn.Disconnect();
publisherConn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergePullSubscription
Try
' Connect to the Subscriber.
subscriberConn.Connect()
' Ensure that the publication exists and that
' it supports pull subscriptions.
publication = New MergePublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = publisherConn
If publication.LoadProperties() Then
If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPull
End If
' Define the pull subscription.
subscription = New MergePullSubscription()
subscription.ConnectionContext = subscriberConn
subscription.PublisherName = publisherName
subscription.PublicationName = publicationName
subscription.PublicationDBName = publicationDbName
subscription.DatabaseName = subscriptionDbName
' Specify that an agent job not be created for this subscription. The
' subscription can only be synchronized by running the Merge Agent directly.
' Subscripition metadata stored in MSsubscription_properties will not
' be available and must be specified at run time.
subscription.CreateSyncAgentByDefault = False
' Create the pull subscription at the Subscriber.
subscription.Create()
Dim registered As Boolean = False
' Verify that the subscription is not already registered.
For Each existing As MergeSubscription In _
publication.EnumSubscriptions()
If existing.SubscriberName = subscriberName Then
registered = True
End If
Next
If Not registered Then
' Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown( _
subscriberName, subscriptionDbName, _
SubscriptionSyncType.Automatic, _
MergeSubscriberType.Local, 0)
End If
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
subscriberConn.Disconnect()
publisherConn.Disconnect()
End Try
Bu örnek, bir çekme abonelik Web eşitleme kullanarak Internet üzerinden eşitlenebilir birleştirme yayınına oluşturur. Birleştirme Aracısı işi oluşturmak için kullanılan Windows hesabının kimlik bilgileri, çalışma anında iletilir. Daha fazla bilgi için, bkz. Web Eşitleme Yapılandır.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";
string webSyncUrl = "https://" + publisherInstance + "/WebSync/replisapi.dll";
//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);
// Create the objects that we need.
MergePublication publication;
MergePullSubscription subscription;
try
{
// Connect to the Subscriber.
subscriberConn.Connect();
// Ensure that the publication exists and that
// it supports pull subscriptions and Web synchronization.
publication = new MergePublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = publisherConn;
if (publication.LoadProperties())
{
if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPull;
}
if ((publication.Attributes & PublicationAttributes.AllowWebSynchronization) == 0)
{
publication.Attributes |= PublicationAttributes.AllowWebSynchronization;
}
// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = subscriberConn;
subscription.PublisherName = publisherName;
subscription.PublicationName = publicationName;
subscription.PublicationDBName = publicationDbName;
subscription.DatabaseName = subscriptionDbName;
subscription.HostName = hostname;
// Specify the Windows login credentials for the Merge Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
subscription.SynchronizationAgentProcessSecurity.Password = winPassword;
// Enable Web synchronization.
subscription.UseWebSynchronization = true;
subscription.InternetUrl = webSyncUrl;
// Specify the same Windows credentials to use when connecting to the
// Web server using HTTPS Basic Authentication.
subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication;
subscription.InternetLogin = winLogin;
subscription.InternetPassword = winPassword;
// Ensure that we create a job for this subscription.
subscription.CreateSyncAgentByDefault = true;
// Create the pull subscription at the Subscriber.
subscription.Create();
Boolean registered = false;
// Verify that the subscription is not already registered.
foreach (MergeSubscription existing
in publication.EnumSubscriptions())
{
if (existing.SubscriberName == subscriberName
&& existing.SubscriptionDBName == subscriptionDbName
&& existing.SubscriptionType == SubscriptionOption.Pull)
{
registered = true;
}
}
if (!registered)
{
// Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown(
subscriberName, subscriptionDbName,
SubscriptionSyncType.Automatic,
MergeSubscriberType.Local, 0);
}
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
subscriberConn.Disconnect();
publisherConn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/WebSync/replisapi.dll"
'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergePullSubscription
Try
' Connect to the Subscriber.
subscriberConn.Connect()
' Ensure that the publication exists and that
' it supports pull subscriptions and Web synchronization.
publication = New MergePublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = publisherConn
If publication.LoadProperties() Then
If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPull
End If
If (publication.Attributes And PublicationAttributes.AllowWebSynchronization) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowWebSynchronization
End If
' Define the pull subscription.
subscription = New MergePullSubscription()
subscription.ConnectionContext = subscriberConn
subscription.PublisherName = publisherName
subscription.PublicationName = publicationName
subscription.PublicationDBName = publicationDbName
subscription.DatabaseName = subscriptionDbName
subscription.HostName = hostname
subscription.CreateSyncAgentByDefault = True
' Specify the Windows login credentials for the Merge Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin
subscription.SynchronizationAgentProcessSecurity.Password = winPassword
' Enable Web synchronization.
subscription.UseWebSynchronization = True
subscription.InternetUrl = webSyncUrl
' Specify the same Windows credentials to use when connecting to the
' Web server using HTTPS Basic Authentication.
subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
subscription.InternetLogin = winLogin
subscription.InternetPassword = winPassword
' Create the pull subscription at the Subscriber.
subscription.Create()
Dim registered As Boolean = False
' Verify that the subscription is not already registered.
For Each existing As MergeSubscription In _
publication.EnumSubscriptions()
If existing.SubscriberName = subscriberName Then
registered = True
End If
Next
If Not registered Then
' Register the local subscription with the Publisher.
publication.MakePullSubscriptionWellKnown( _
subscriberName, subscriptionDbName, _
SubscriptionSyncType.Automatic, _
MergeSubscriberType.Local, 0)
End If
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
subscriberConn.Disconnect()
publisherConn.Disconnect()
End Try
[Top]
Ayrıca bkz.
Kavramlar
Çoğaltma Management Objects kavramları