Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MergePartition Class


Represents information about a Subscriber's partition for a merge publication with a parameterized row filter.

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


public sealed class MergePartition


Creates a new instance of the MergePartition class.


Gets or sets the date and time when the data snapshot of the partition was generated.


Gets or sets the value supplied to the HOST_NAME (Transact-SQL) function to generate the data snapshot, when the parameterized row filter is defined using this function.


Gets or sets the value supplied to the SUSER_SNAME (Transact-SQL) function to generate the data snapshot, when the parameterized row filter is defined using this function.


Gets or sets the Microsoft SQL Server Agent job ID, in hexadecimal format, which generates the filtered snapshot for the Subscriber.


Gets or sets the operating system folder used to store the filtered snapshot generated for the partition.


Gets or sets the ID value that uniquely identifies the partition.


Gets or sets an object that allows you to attach custom data to this instance of MergePartition.


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)

This namespace, class, or member is supported only in version 2.0 of the Microsoft .NET Framework.

Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";
string distributorName = publisherInstance;

MergePublication publication;
MergePartition partition;
MergeDynamicSnapshotJob snapshotAgentJob;
ReplicationAgentSchedule schedule;

// Create a connection to the Publisher.
ServerConnection publisherConn = new ServerConnection(publisherName);

// Create a connection to the Distributor to start the Snapshot Agent.
ServerConnection distributorConn = new ServerConnection(distributorName);

	// Connect to the Publisher.

	// Set the required properties for the publication.
	publication = new MergePublication();
	publication.ConnectionContext = publisherConn;
	publication.Name = publicationName;
	publication.DatabaseName = publicationDbName;

	// If we can't get the properties for this merge publication, 
	// then throw an application exception.
	if (publication.LoadProperties() || publication.SnapshotAvailable)
		// Set a weekly schedule for the filtered data snapshot.
		schedule = new ReplicationAgentSchedule();
		schedule.FrequencyType = ScheduleFrequencyType.Weekly;
		schedule.FrequencyRecurrenceFactor = 1;
		schedule.FrequencyInterval = Convert.ToInt32(0x001);

		// Set the value of Hostname that defines the data partition. 
		partition = new MergePartition();
		partition.DynamicFilterHostName = hostname;
		snapshotAgentJob = new MergeDynamicSnapshotJob();
		snapshotAgentJob.DynamicFilterHostName = hostname;

		// Create the partition for the publication with the defined schedule.
		publication.AddMergeDynamicSnapshotJob(snapshotAgentJob, schedule);
		throw new ApplicationException(String.Format(
			"Settings could not be retrieved for the publication, " +
			" or the initial snapshot has not been generated. " +
			"Ensure that the publication {0} exists on {1} and " +
			"that the Snapshot Agent has run successfully.",
			publicationName, publisherName));
catch (Exception ex)
	// Do error handling here.
	throw new ApplicationException(string.Format(
		"The partition for '{0}' in the {1} publication could not be created.",
		hostname, publicationName), ex);
	if (distributorConn.IsOpen) distributorConn.Disconnect();

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft