Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
A következőkre vonatkozik:SQL Server
Azure SQL Managed Instance
Ez a téma bemutatja, hogyan lehet pull előfizetést létrehozni az SQL Server-ben az SQL Server Management Studio, Transact-SQL vagy Replication Management Objects (RMO) használatával.
A P2P replikációhoz pull előfizetés beállítása script segítségével lehetséges, de a varázslón keresztül nem elérhető.
Az SQL Server Management Studio használata
Hozz létre pull előfizetést a Publisher-nél vagy az Előfizetőnél az Új Előfizetés Varázslóval. Kövesse a varázsló lapjait a következőhöz:
Adja meg a Közzétevőt és a kiadványt.
Válassza ki, hogy a replikációs ügynökök hol fognak futni. Lekéréses előfizetés esetén a közzététel típusától függően válassza a Terjesztési ügynök helye vagy a Egyesítési ügynök helye lapon a Mindegyik ügynök futtatása az előfizetőnél (lekéréses előfizetések) beállítást.
Adja meg az előfizetőket és az előfizetési adatbázisokat.
Adja meg a replikációs ügynökök által létrehozott kapcsolatokhoz használt bejelentkezéseket és jelszavakat:
A pillanatfelvételekre és tranzakciós kiadványokra való előfizetésekhez adja meg a hitelesítő adatokat a Terjesztési ügynök biztonsági beállításai oldalán.
A kiadványokat egyesítő előfizetésekhez adja meg a hitelesítő adatokat az Ügynök egyesítése biztonsági oldalon.
Az egyes ügynökök által igényelt engedélyekkel kapcsolatos információkért tekintse meg a replikációs ügynök biztonsági modelljét.
Adja meg a szinkronizálás ütemezését, és hogy mikor kell inicializálni az előfizetőt.
Határozz meg további opciókat a kiadványok összevonásához: előfizetési típus; paraméterezett szűréshez szükséges értékeket; valamint információt a HTTPS segítségével történő szinkronizáláshoz, ha a publikáció engedélyezett a webes szinkronizációra.
Adja meg a frissíthető előfizetéseket lehetővé tevő tranzakciós közzétételek további beállításait: hogy az Előfizetők azonnal véglegesítsék-e a módosításokat a Közzétevőnél, vagy várólistába írják azokat; valamint az Előfizetőtől a Közzétevőhöz való csatlakozáshoz használt hitelesítő adatokat.
Opcionálisan scripteld az előfizetést.
Lekéréses előfizetés létrehozása a Közzétevőtől
Csatlakozzon a Publisherhez a Microsoft SQL Server Management Studióban, majd bontsa ki a kiszolgálócsomópontot.
Bontsa ki a Replikáció mappát, majd bontsa ki a Helyi kiadványok mappát.
Jobb kattints arra a kiadványra, amelyhez egy vagy több előfizetést szeretnél létrehozni, majd kattints az Új előfizetések gombra.
Töltse ki a lapokat az Új előfizetés varázslóban.
Lekéréses feliratkozás létrehozása az Előfizetőből
Csatlakozzon az előfizetőhöz az SQL Server Management Studióban, majd bontsa ki a kiszolgálócsomópontot.
Nyissa meg a Replikáció mappát.
Kattintson a jobb gombbal a Helyi előfizetések mappára, majd az Új előfizetések parancsra.
Az Új Előfizetési Varázsló Publikáció oldalán válaszd <a Find SQL Server Publisher> vagy <Find Oracle Publisher> menüt a Publisher legördülő listából.
Csatlakozás a Publisherhez a Csatlakozás a kiszolgálóhoz párbeszédpanelen.
Válasszon ki egy kiadványt a Kiadvány lapon.
Töltse ki a lapokat az Új előfizetés varázslóban.
Transact-SQL használata
A lekéréses előfizetések programozottan hozhatók létre a replikáció tárolt eljárásaival. A használt tárolt eljárások attól függenek, hogy milyen típusú kiadványhoz tartozik az előfizetés.
Lekéréses előfizetés létrehozása pillanatkép- vagy tranzakciós közzétételhez
A Közzétevőnél az sp_helppublication (Transact-SQL) végrehajtásával ellenőrizze, hogy a kiadvány támogatja-e a lekéréses előfizetéseket.
Ha az eredményhalmazban allow_pullértéke 1, akkor a kiadvány támogatja a pull előfizetéseket.
Ha a allow_pull értéke 0, hajtsa végre a(z) sp_changepublication (Transact-SQL) utasítást úgy, hogy a(z) @property értéke allow_pull, a(z) @value értéke pedig true.
A Feliratkozó esetében hajtsd végre a sp_addpullsubscription (Transact-SQL) parancsot. Határozd meg @publisher és @publication. Az előfizetések frissítéséről további információért lásd: Frissíthető előfizetés létrehozása tranzakciós kiadványhoz.
A Feliratkozó esetén hajtsd végre a sp_addpullsubscription_agent (Transact-SQL) parancsot. Adja meg a következőket:
A @publisher, @publisher_db és @publication paraméterek.
A Microsoft Windows hitelességek, amelyek alatt az Subscriber Distribution Agent @job_login és @job_password fut.
Megjegyzés:
Az Windows integrált hitelesítéssel létrejött kapcsolatok mindig a @job_login és @job_password által meghatározott Windows hitelesítést használják. A terjesztési ügynök mindig a Windows integrált hitelesítés használatával hozza létre a helyi kapcsolatot az előfizetővel. Alapértelmezés szerint az ügynök a Windows integrált hitelesítéssel csatlakozik a Forgalmazóhoz.
(Opcionális) A @distributor_security_modeértéke 0, @distributor_login és @distributor_password esetén pedig a SQL Server bejelentkezési adatok, ha SQL Server hitelesítést kell használni a Forgalmazóhoz való csatlakozáskor.
Az előfizetés terjesztési ügynök feladatának ütemezése. További információ: Szinkronizálási ütemezések megadása.
A Publisher után hajtsd végre a sp_addsubscription (Transact-SQL) parancsot a pull előfizetés regisztrálásához. Adja meg @publication, @subscriber és @destination_db. Adja meg a lekérés értéket @subscription_type számára.
Lekéréses előfizetés létrehozása egy egyesítéses közzétételhez
A Közzétevőn ellenőrizze, hogy a közzététel támogatja-e a pull-előfizetéseket a sp_helpmergepublication (Transact-SQL) végrehajtásával.
Ha az eredményhalmazban allow_pullértéke 1, akkor a kiadvány támogatja a pull előfizetéseket.
Ha a(z) allow_pull értéke 0, futtassa a(z) sp_changemergepublication (Transact-SQL) parancsot, és adja meg a(z) allow_pull értéket a(z) @property paraméterhez, valamint a(z) true értéket a(z) @value paraméterhez.
A Feliratkozó esetén hajtsd végre a sp_addmergepullsubscription (Transact-SQL) parancsot. Adja meg a @publisher, @publisher_db, @publication és az alábbi paramétereket:
@subscriber_type – megadja a helyi kliens előfizetéshez, a globális szerver előfizetéshez.
@subscription_priority - Határozz meg prioritást az előfizetéshez (0,00 és 99,99 között). Ez csak szerver előfizetéshez szükséges.
További információkért lásd: Az egyesítéses replikáció speciális ütközésészlelése és -feloldása.
A Feliratkozó esetében hajtsd végre sp_addmergepullsubscription_agent (Transact-SQL) parancsot. Adja meg a következő paramétereket:
@publisher, @publisher_db és @publication.
A Windows hitelességek, amelyek alatt az Előfizető Merge Agent @job_login és @job_password fut.
Megjegyzés:
Az Windows integrált hitelesítéssel létrejött kapcsolatok mindig a @job_login és @job_password által meghatározott Windows hitelesítést használják. A Merge Agent mindig helyi kapcsolatot teremt az Előfizetővel a Windows integrált hitelesítéssel. Alapértelmezés szerint az ügynök a Windows integrált hitelesítéssel csatlakozik a Forgalmazóhoz és a Publisher-hez.
(Opcionális) A @distributor_security_modeértéke 0, @distributor_login és @distributor_password esetén pedig a SQL Server bejelentkezési adatok, ha SQL Server hitelesítést kell használni a Forgalmazóhoz való csatlakozáskor.
(Választható) A 0 érték a @publisher_security_mode paraméterhez, valamint az SQL Server bejelentkezési információi a @publisher_login és a @publisher_password paraméterhez, ha az SQL Server-hitelesítést kell használnia a Közzétevőhöz való csatlakozáskor.
Az ennek az előfizetésnek szóló Merge Agent feladat ütemezése. További információért lásd: Frissíthető előfizetés létrehozása tranzakciós kiadványhoz.
A Publisher esetén hajtsd végre sp_addmergesubscription (Transact-SQL). Adja meg a @publication, @subscriber, @subscriber_db paramétereket, valamint a(z) @subscription_type paraméterhez a pull értéket. Ez regisztrálja a lekéréses előfizetést.
Példák (Transact-SQL)
A következő példa egy pull előfizetést hoz létre egy tranzakciós kiadványhoz. Az első kötetet a Subscriber-nél hajtják végre, a második részt pedig a Publisher-nél. A bejelentkezési és jelszóértékek futásidőben jelennek meg sqlcmd szkriptelési változók használatával.
-- 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'AdventureWorks';
-- At the subscription database, create a pull subscription
-- to a transactional publication.
USE [AdventureWorksReplica]
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'AdventureWorksReplica';
-- 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 következő példa egy pull előfizetést hoz létre egy egyesítő kiadványhoz. Az első kötetet a Subscriber-nél hajtják végre, a második részt pedig a Publisher-nél. A bejelentkezési és jelszóértékeket futásidőben sqlcmd szkriptváltozókkal szolgáltatják.
-- 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'AdventureWorks';
SET @hostname = N'adventure-works\david8';
-- At the subscription database, create a pull subscription
-- to a merge publication.
USE [AdventureWorksReplica]
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'AdventureWorksReplica';
-- At the Publisher, register the subscription, using the defaults.
USE [AdventureWorks]
EXEC sp_addmergesubscription @publication = @myMergePub,
@subscriber = @mySub, @subscriber_db = @mySubDB,
@subscription_type = N'pull';
GO
Replikációkezelési objektumok (RMO) használata
Az RMO osztályok, amelyeket a pull előfizetés létrehozásához használnak, attól függnek, milyen kiadványhoz tartozik az előfizetés.
Lekéréses előfizetés létrehozása pillanatkép- vagy tranzakciós közzétételhez
Hozzon létre kapcsolatokat az előfizetővel és a Publisherrel is az ServerConnection osztály használatával.
Példányosítsa az TransPublication osztályt az 1. lépésben használt Publisher-kapcsolat segítségével. Adja meg a Name, DatabaseName és ConnectionContext elemeket.
Hívja meg a LoadProperties metódust. Ha ez a metódus hamis értéket ad vissza, a 2. lépésben megadott tulajdonságok helytelenek, vagy a kiadvány nem létezik a kiszolgálón.
Bitenkénti logikai ÉS művelet végrehajtása (& a Visual C# nyelvben és And a Visual Basic nyelvben) a Attributes tulajdonság és AllowPull között. Ha az eredmény None, állítsa be Attributes értékét az | és közötti bitenkénti logikai OR művelet eredményére (Attributes a Visual C#-ben és AllowPull a Visual Basic-ben). Ezután hívj CommitPropertyChanges fel, hogy engedélyezd a pull előfizetéseket.
Ha az előfizetési adatbázis nem létezik, hozza létre az Database osztály használatával. További információért lásd: Adatbázisok létrehozása, módosítása és eltávolítása.
Hozzon létre egy példányt a TransPullSubscription osztályból.
Adja meg a következő előfizetési tulajdonságokat:
Az ServerConnection előfizető számára az 1. lépésben létrehozva .ConnectionContext
A(z) előfizetési adatbázisának DatabaseNameneve.
A(z) PublisherName kiadójának neve.
A következő kiadvány adatbázisa neve: PublicationDBName
A kiadvány neve a következőhöz PublicationName: .
A Login és Password mezők SynchronizationAgentProcessSecurity megadják a Microsoft Windows fiók hitelesítését, amelyen a Distribution Agent az Előfizetőnél fut. Ezt a fiókot helyi kapcsolatok létrehozására használják az előfizetővel, valamint távoli kapcsolatok létrehozására a Windows hitelesítéssel.
Megjegyzés:
A beállítás SynchronizationAgentProcessSecurity nem szükséges, ha az előfizetést a rendszergazdi fix szerver tagja hozza létre, azonban ajánlott. Ebben az esetben az ügynök megszemélyesíti az SQL Server Agent-fiókot. További információ: Replikációs ügynök biztonsági modellje.
(Nem kötelező) A(z) CreateSyncAgentByDefaulttrue értéke egy, az előfizetés szinkronizálására szolgáló ügynökfeladat létrehozását eredményezi. Ha a false értéket adod meg (ez az alapértelmezés), az előfizetés csak programból szinkronizálható, és a SynchronizationAgent tulajdonságon keresztül elért objektum használatakor meg kell adnod a TransSynchronizationAgent további tulajdonságait is. További információ: Lekéréses előfizetés szinkronizálása.
Megjegyzés:
Az SQL Server Agent nem érhető el minden SQL Server kiadásban. Ha az Express Subscribers esetében a true értéket adja meg, az ügynökfeladat nem jön létre. Azonban fontos előfizetéssel kapcsolatos metaadatok az Előfizetőnél tárolódnak. Az SQL Server kiadásai által támogatott funkciók listájáért lásd: Az SQL Server 2025 Kiadásai és támogatott funkciói.
(Opcionális) Állítsd be az SqlStandardLogin és SqlStandardPassword vagy SecureSqlStandardPassword mezőketDistributorSecurity, amikor SQL Server hitelesítést használsz, hogy csatlakozzon a Distributorhoz.
Hívja meg a Create metódust.
A 2. lépésből származó osztály példányát TransPublication használva hívjuk meg a MakePullSubscriptionWellKnown metódust, hogy regisztráljuk a pull előfizetést a Publisher-nél. Ha ez a regisztráció már létezik, kivétel történik.
Lekéréses előfizetés létrehozása egy egyesítéses közzétételhez
Hozz létre kapcsolatokat mind az előfizetővel, mind a közzétevővel a ServerConnection osztály használatával.
Példányosítsa az MergePublication osztályt az 1. lépésben használt Publisher-kapcsolat segítségével. Adja meg Namea , DatabaseNameés ConnectionContexta .
Hívja meg a LoadProperties metódust. Ha ez a metódus hamis értéket ad vissza, a 2. lépésben megadott tulajdonságok helytelenek, vagy a kiadvány nem létezik a kiszolgálón.
Bitenkénti logikai ÉS művelet végrehajtása (& a Visual C# nyelvben és And a Visual Basic nyelvben) a Attributes tulajdonság és AllowPull között. Ha az eredmény None, állítsa be Attributes értékét az | és közötti bitenkénti logikai OR művelet eredményére (Attributes a Visual C#-ben és AllowPull a Visual Basic-ben). Ezután hívj CommitPropertyChanges fel, hogy engedélyezd a pull előfizetéseket.
Ha az előfizetési adatbázis nem létezik, hozza létre az Database osztály használatával. További információért lásd: Adatbázisok létrehozása, módosítása és eltávolítása.
Hozzon létre egy példányt a MergePullSubscription osztályból.
Adja meg a következő előfizetési tulajdonságokat:
A ServerConnection az 1. lépésben létrehozott Előfizetőhöz a(z) ConnectionContext számára.
A(z) előfizetési adatbázisának DatabaseNameneve.
PublisherName kiadójának neve.
A következő kiadvány adatbázisa neve: PublicationDBName
A kiadvány neve a következőhöz PublicationName: .
A Login és Password mezők SynchronizationAgentProcessSecurity a Microsoft Windows fiók hitelesítésének megadására szolgálnak, amelyen a Merge Agent az Előfizetőnél fut. Ezt a fiókot helyi kapcsolatok létrehozására használják az előfizetővel, valamint távoli kapcsolatok létrehozására a Windows hitelesítéssel.
Megjegyzés:
A beállítás SynchronizationAgentProcessSecurity nem szükséges, ha az előfizetést a rendszergazdi fix szerver tagja hozza létre, azonban ajánlott. Ebben az esetben az ügynök megszemélyesíti az SQL Server Agent-fiókot. További információ: Replikációs ügynök biztonsági modellje.
(Nem kötelező) A CreateSyncAgentByDefault értékének true-ra állítása egy olyan ügynökfeladat létrehozásához, amely az előfizetés szinkronizálására szolgál. Ha a false értéket adod meg (ez az alapértelmezett), az előfizetés csak programból szinkronizálható, és meg kell adnod a MergeSynchronizationAgent további tulajdonságait, amikor ezt az objektumot a SynchronizationAgent tulajdonságon keresztül éred el. További információ: Lekéréses előfizetés szinkronizálása.
(Nem kötelező) Állítsa be a DistributorSecuritySqlStandardLogin és SqlStandardPassword vagy SecureSqlStandardPassword mezőit, amikor SQL Server-hitelesítést használ a Terjesztőhöz való csatlakozáshoz.
(Nem kötelező) Állítsa be a PublisherSecuritySqlStandardLogin és SqlStandardPassword vagy SecureSqlStandardPassword mezőit, amikor SQL Server-hitelesítést használ a Publisherhez való csatlakozáshoz.
Hívja meg a Create metódust.
A 2. lépésből származó osztály példányát MergePublication használva hívjuk meg a MakePullSubscriptionWellKnown metódust, hogy regisztráljuk a pull előfizetést a Publisher-nél. Ha ez a regisztráció már létezik, kivétel történik.
Példa (RMO)
Ez a példa pull előfizetést hoz létre egy tranzakciós kiadványhoz. A Distribution Agent-feladat létrehozásához használt Microsoft Windows-fiók hitelesítő adatait a rendszer futásidőben adja át.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksProductTran";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
//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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
'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
Ez a példa pull előfizetést hoz létre egy egyesítő kiadványhoz. A Windows fiók hitelesítő adatait, amelyeket a Merge Agent munka létrehozásához használnak, futásidőben továbbítják.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
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
Ez a példa lekéréses előfizetést hoz létre egy egyesítéses közzétételhez anélkül, hogy létrehozná a hozzá tartozó ügynökfeladatot és az előfizetési metaadatokat a MSsubscription_properties táblában. A Windows fiók hitelesítő adatait, amelyeket a Merge Agent munka létrehozásához használnak, futásidőben továbbítják.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
//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.
// Subscription 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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
'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.
' Subscription 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
Ez a példa egy pull előfizetést hoz létre egy egyesült kiadványhoz, amely interneten keresztül szinkronizálható webes szinkronizációval. A Windows fiók hitelesítő adatait, amelyeket a Merge Agent munka létrehozásához használnak, futásidőben továbbítják. További információért lásd: Web szinkronizáció konfigurálása.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
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