MergePublication Class
マージ パブリケーションを表します。
名前空間: Microsoft.SqlServer.Replication
アセンブリ: Microsoft.SqlServer.Rmo (microsoft.sqlserver.rmo.dll 内)
構文
'宣言
Public NotInheritable Class MergePublication
Inherits Publication
public sealed class MergePublication : Publication
public ref class MergePublication sealed : public Publication
public final class MergePublication extends Publication
public final class MergePublication extends Publication
解説
この名前空間、クラス、またはメンバは、Microsoft .NET Framework 2.0 でのみサポートされています。
継承階層
System.Object
Microsoft.SqlServer.Replication.ReplicationObject
Microsoft.SqlServer.Replication.Publication
Microsoft.SqlServer.Replication.MergePublication
使用例
この例では、マージ パブリケーションを作成します。
// Set the Publisher, publication database, and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks";
ReplicationDatabase publicationDb;
MergePublication publication;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Enable the database for merge publication.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (!publicationDb.EnabledMergePublishing)
{
publicationDb.EnabledMergePublishing = true;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The {0} database does not exist on {1}.",
publicationDb, publisherName));
}
// Set the required properties for the merge publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Enable precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True;
// Specify the Windows account under which the Snapshot Agent job runs.
// This account will be used for the local connection to the
// Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin;
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;
// Explicitly set the security mode for the Publisher connection
// Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;
// Enable Subscribers to request snapshot generation and filtering.
publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
publication.Attributes |= PublicationAttributes.DynamicFilters;
// Enable pull and push subscriptions.
publication.Attributes |= PublicationAttributes.AllowPull;
publication.Attributes |= PublicationAttributes.AllowPush;
if (!publication.IsExistingObject)
{
// Create the merge publication.
publication.Create();
// Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent();
}
else
{
throw new ApplicationException(String.Format(
"The {0} publication already exists.", publicationName));
}
}
catch (Exception ex)
{
// Implement custom application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be created.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Set the Publisher, publication database, and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks"
Dim publicationDb As ReplicationDatabase
Dim publication As MergePublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Enable the database for merge publication.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If Not publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = True
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The {0} database does not exist on {1}.", _
publicationDb, publisherName))
End If
' Set the required properties for the merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Enable precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True
' Specify the Windows account under which the Snapshot Agent job runs.
' This account will be used for the local connection to the
' Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword
' Explicitly set the security mode for the Publisher connection
' Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = True
' Enable Subscribers to request snapshot generation and filtering.
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowSubscriberInitiatedSnapshot
publication.Attributes = publication.Attributes Or _
PublicationAttributes.DynamicFilters
' Enable pull and push subscriptions
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPull
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPush
If Not publication.IsExistingObject Then
' Create the merge publication.
publication.Create()
' Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent()
Else
Throw New ApplicationException(String.Format( _
"The {0} publication already exists.", publicationName))
End If
Catch ex As Exception
' Implement custom application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be created.", publicationName), ex)
Finally
conn.Disconnect()
End Try
この例では、マージ パブリケーションのプロパティを変更します。
// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks";
MergePublication publication;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
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())
{
// If DDL replication is currently enabled, disable it.
if (publication.ReplicateDdl == DdlReplicationOptions.All)
{
publication.ReplicateDdl = DdlReplicationOptions.None;
}
else
{
publication.ReplicateDdl = DdlReplicationOptions.All;
}
}
else
{
throw new ApplicationException(String.Format(
"Settings could not be retrieved for the publication. " +
"Ensure that the publication {0} exists on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Do error handling here.
throw new ApplicationException(
"The publication property could not be changed.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks"
Dim publication As MergePublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Set the required properties for the publication.
publication = New MergePublication()
publication.ConnectionContext = conn
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() Then
' If DDL replication is currently enabled, disable it.
If publication.ReplicateDdl = DdlReplicationOptions.All Then
publication.ReplicateDdl = DdlReplicationOptions.None
Else
publication.ReplicateDdl = DdlReplicationOptions.All
End If
Else
Throw New ApplicationException(String.Format( _
"Settings could not be retrieved for the publication. " + _
"Ensure that the publication {0} exists on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Do error handling here.
Throw New ApplicationException( _
"The publication property could not be changed.", ex)
Finally
conn.Disconnect()
End Try
この例では、マージ パブリケーションを削除します。
// Define the Publisher, publication database,
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks";
MergePublication publication;
ReplicationDatabase publicationDb;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the merge publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Delete the publication, if it exists and has no subscriptions.
if (publication.LoadProperties() && !publication.HasSubscription)
{
publication.Remove();
}
else
{
// Do something here if the publication does not exist
// or has subscriptions.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted. " +
"Ensure that the publication exists and that all " +
"subscriptions have been deleted.",
publicationName, publisherName));
}
// If no other merge publications exists,
// disable publishing on the database.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (publicationDb.MergePublications.Count == 0 && publicationDb.EnabledMergePublishing)
{
publicationDb.EnabledMergePublishing = false;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The database {0} does not exist on {1}.",
publicationDbName, publisherName));
}
}
catch (Exception ex)
{
// Implement application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted.",
publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication database,
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks"
Dim publication As MergePublication
Dim publicationDb As ReplicationDatabase
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Set the required properties for the merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Delete the publication, if it exists and has no subscriptions.
If (publication.LoadProperties() And Not publication.HasSubscription) Then
publication.Remove()
Else
' Do something here if the publication does not exist
' or has subscriptions.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted. " + _
"Ensure that the publication exists and that all " + _
"subscriptions have been deleted.", _
publicationName, publisherName))
End If
' If no other merge publications exists,
' disable publishing on the database.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If publicationDb.MergePublications.Count = 0 _
And publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = False
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The database {0} does not exist on {1}.", _
publicationDbName, publisherName))
End If
Catch ex As Exception
' Implement application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted.", _
publicationName), ex)
Finally
conn.Disconnect()
End Try
スレッド セーフ
この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム
開発プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
対象プラットフォーム
サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。
参照
関連項目
MergePublication Members
Microsoft.SqlServer.Replication Namespace
その他の技術情報
パブリケーションを作成する方法 (RMO プログラミング)
パブリケーション プロパティの表示と変更の方法 (RMO プログラミング)