Questa pagina è stata utile?
I suggerimenti relativi al contenuto di questa pagina sono importanti. Comunicaceli.
Altri suggerimenti?
1500 caratteri rimanenti
Esporta (0) Stampa
Espandi tutto
EN
Il contenuto non è disponibile nella lingua di destinazione, ma solo in inglese.

PullSubscription.CreateSyncAgentByDefault Property

 

Applies To: SQL Server 2016 Preview

Gets or sets whether or not the agent job used to start the Replication Agent to synchronize the subscription is created when the subscription is created.

Namespace:   Microsoft.SqlServer.Replication
Assembly:  Microsoft.SqlServer.Rmo (in Microsoft.SqlServer.Rmo.dll)

public bool CreateSyncAgentByDefault { get; set; }

Property Value

Type: System.Boolean

true if synchronization is created; otherwise, false.

CreateSyncAgentByDefault defaults to false.

Specify a value of true for CreateSyncAgentByDefault when you need to schedule synchronization, or when you need to synchronize the subscription from SQL Server Management Studio. Specify a value of false if the Replication Agent will always be started programmatically without using SQL Server Agent.

When you specify a value of false for CreateSyncAgentByDefault, the MergeSynchronizationAgent or TransSynchronizationAgent objects obtained from the SynchronizationAgent or SynchronizationAgent properties will not have enough information to successfully synchronize the subscription. For more information, see .

Specifying a value of false for CreateSyncAgentByDefault and calling Create is equivalent to executing sp_addpullsubscription (Transact-SQL) without executing sp_addpullsubscription_agent (Transact-SQL) or executing sp_addmergepullsubscription (Transact-SQL) without executing sp_addmergepullsubscription_agent (Transact-SQL).

Legacy Code Example

This example creates a pull subscription to a merge publication, along with the agent job to synchronize the subscription and related metadata.

			// 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();
			}

This example creates a pull subscription to a merge publication, but the agent job to synchronize the subscription and related metadata are not created.

			// 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();
			}
Return to top
Microsoft sta conducendo un sondaggio in linea per comprendere l'opinione degli utenti in merito al sito Web di MSDN. Se si sceglie di partecipare, quando si lascia il sito Web di MSDN verrà visualizzato il sondaggio in linea.

Si desidera partecipare?
Mostra:
© 2015 Microsoft