TransPublication 類別

定義

代表交易性出版物。

public ref class TransPublication sealed : Microsoft::SqlServer::Replication::Publication
public sealed class TransPublication : Microsoft.SqlServer.Replication.Publication
type TransPublication = class
    inherit Publication
Public NotInheritable Class TransPublication
Inherits Publication
繼承

範例

此範例產生交易性出版物。

// Set the Publisher, publication database, and publication names.
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
string publisherName = publisherInstance;

ReplicationDatabase publicationDb;
TransPublication publication;

// Create a connection to the Publisher using Windows Authentication.
ServerConnection conn;
conn = new ServerConnection(publisherName);


try
{
    // Connect to the Publisher.
    conn.Connect();

    // Enable the AdventureWorks2012 database for transactional publishing.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);

    // If the database exists and is not already enabled, 
    // enable it for transactional publishing.
    if (publicationDb.LoadProperties())
    {
        if (!publicationDb.EnabledTransPublishing)
        {
            publicationDb.EnabledTransPublishing = true;
        }

        // If the Log Reader Agent does not exist, create it.
        if (!publicationDb.LogReaderAgentExists)
        {
            // Specify the Windows account under which the agent job runs.
            // This account will be used for the local connection to the 
            // Distributor and all agent connections that use Windows Authentication.
            publicationDb.LogReaderAgentProcessSecurity.Login = winLogin;
            publicationDb.LogReaderAgentProcessSecurity.Password = winPassword;

            // Explicitly set authentication mode for the Publisher connection
            // to the default value of Windows Authentication.
            publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = true;

            // Create the Log Reader Agent job.
            publicationDb.CreateLogReaderAgent();
        }
    }
    else
    {
        throw new ApplicationException(String.Format(
            "The {0} database does not exist at {1}.",
            publicationDb, publisherName));
    }

    // Set the required properties for the transactional publication.
    publication = new TransPublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;

    // Specify a transactional publication (the default).
    publication.Type = PublicationType.Transactional;

    // Activate the publication so that we can add subscriptions.
    publication.Status = State.Active;

    // Enable push and pull subscriptions and independent Distribition Agents.
    publication.Attributes |= PublicationAttributes.AllowPull;
    publication.Attributes |= PublicationAttributes.AllowPush;
    publication.Attributes |= PublicationAttributes.IndependentAgent;

    // 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;

    if (!publication.IsExistingObject)
    {
        // Create the transactional 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 publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publisherName As String = publisherInstance

Dim publicationDb As ReplicationDatabase
Dim publication As TransPublication

' Create a connection to the Publisher using Windows Authentication.
Dim conn As ServerConnection
conn = New ServerConnection(publisherName)

Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Enable the AdventureWorks2012 database for transactional publishing.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)

    ' If the database exists and is not already enabled, 
    ' enable it for transactional publishing.
    If publicationDb.LoadProperties() Then
        If Not publicationDb.EnabledTransPublishing Then
            publicationDb.EnabledTransPublishing = True
        End If

        ' If the Log Reader Agent does not exist, create it.
        If Not publicationDb.LogReaderAgentExists Then
            ' Specify the Windows account under which the agent job runs.
            ' This account will be used for the local connection to the 
            ' Distributor and all agent connections that use Windows Authentication.
            publicationDb.LogReaderAgentProcessSecurity.Login = winLogin
            publicationDb.LogReaderAgentProcessSecurity.Password = winPassword

            ' Explicitly set authentication mode for the Publisher connection
            ' to the default value of Windows Authentication.
            publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = True

            ' Create the Log Reader Agent job.
            publicationDb.CreateLogReaderAgent()
        End If
    Else
        Throw New ApplicationException(String.Format( _
         "The {0} database does not exist at {1}.", _
         publicationDb, publisherName))
    End If

    ' Set the required properties for the transactional publication.
    publication = New TransPublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Specify a transactional publication (the default).
    publication.Type = PublicationType.Transactional

    'Enable push and pull subscriptions and independent Distribition Agents.
    publication.Attributes = _
    publication.Attributes Or PublicationAttributes.AllowPull
    publication.Attributes = _
    publication.Attributes Or PublicationAttributes.AllowPush
    publication.Attributes = _
    publication.Attributes Or PublicationAttributes.IndependentAgent

    ' Activate the publication so that we can add subscriptions.
    publication.Status = State.Active

    ' 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

    If Not publication.IsExistingObject Then
        ' Create the transactional 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 Publisher, publication database, 
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";

TransPublication publication;
ReplicationDatabase publicationDb;

// Create a connection to the Publisher 
// using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);

try
{
    conn.Connect();

    // Set the required properties for the transactional publication.
    publication = new TransPublication();
    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 transactional publications exists,
    // disable publishing on the database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.TransPublications.Count == 0)
        {
            publicationDb.EnabledTransPublishing = 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 = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As TransPublication
Dim publicationDb As ReplicationDatabase

' Create a connection to the Publisher 
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    conn.Connect()

    ' Set the required properties for the transactional publication.
    publication = New TransPublication()
    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 transactional publications exists,
    ' disable publishing on the database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)
    If publicationDb.LoadProperties() Then
        If publicationDb.TransPublications.Count = 0 Then
            publicationDb.EnabledTransPublishing = 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

備註

線程安全性

任何此類的公開靜態(SharedMicrosoft Visual Basic)成員對多執行緒操作都是安全的。 任何實例成員都不保證具有執行緒安全性。

建構函式

名稱 Description
TransPublication()

建立 TransPublication 類別的新實例。

TransPublication(String, String, ServerConnection, Boolean)

建立一個具備所需屬性的新TransPublication類別實例,並指示是否已建立該出版的 快照集代理程式 工作。

TransPublication(String, String, ServerConnection)

建立一個具備所需屬性的 TransPublication 類別新實例。

屬性

名稱 Description
AltSnapshotFolder

取得或設定出版物的替代快照檔案位置。

(繼承來源 Publication)
Attributes

取得或設定出版屬性。

(繼承來源 Publication)
CachePropertyChanges

取得或設定是快取複製屬性的變更,還是立即套用。

(繼承來源 ReplicationObject)
CompatibilityLevel

取得或設定該參考出版品能支援的最早 Microsoft SQL Server 版本。

(繼承來源 Publication)
ConflictPolicy

負責制定或設定支援訂閱更新的出版品的衝突政策。

ConflictRetention

取得或設定衝突資料列在衝突資料表中保留的天數。

(繼承來源 Publication)
ConnectionContext

取得或設定連接到 Microsoft SQL Server 實例。

(繼承來源 ReplicationObject)
ContinueOnConflict

判斷在偵測到衝突之後,散發代理程式 是否繼續處理變更。

CreateSnapshotAgentByDefault

如果 快照集代理程式 工作在建立發佈時自動加入,則會被設定或 get。

(繼承來源 Publication)
DatabaseName

取得或設定出版資料庫名稱。

(繼承來源 Publication)
Description

取得或設定出版物的文字描述。

(繼承來源 Publication)
FtpAddress

取得或設定檔案傳輸協定(FTP)伺服器電腦的位址,以支援允許透過 FTP 訂閱初始化的出版品。

(繼承來源 Publication)
FtpLogin

取得或設定登入帳號,用於連接檔案傳輸協定(FTP)伺服器,適用於允許透過 FTP 初始化訂閱的出版。

(繼承來源 Publication)
FtpPassword

設定用於連接檔案傳輸協定(FTP)伺服器的登入密碼,適用於允許透過 FTP 初始化訂閱的出版品。

(繼承來源 Publication)
FtpPort

取得或設定檔案傳輸協定(FTP)伺服器電腦的埠,以支援允許透過 FTP 訂閱初始化的發佈。

(繼承來源 Publication)
FtpSubdirectory

在檔案傳輸協定(FTP)伺服器電腦上取得或設定允許透過 FTP 訂閱初始化的出版品子目錄。

(繼承來源 Publication)
HasSubscription

查看該出版物是否有一個或多個訂閱。

(繼承來源 Publication)
IsExistingObject

它會判斷該物件是否存在於伺服器上。

(繼承來源 ReplicationObject)
Name

取得或設定出版品名稱。

(繼承來源 Publication)
PeerConflictDetectionEnabled

可判斷是否 SetPeerConflictDetection(Boolean, Int32)啟用點對點衝突偵測。

PeerOriginatorID

取得點對點拓撲中節點的 ID;若 PeerConflictDetectionEnabled 將 設定為 true,此 ID 用於衝突偵測。

PostSnapshotScript

取得或設定初始快照套用後執行的 Transact-SQL 腳本檔案名稱及完整路徑。

(繼承來源 Publication)
PreSnapshotScript

取得或設定一個 Transact-SQL 腳本檔案的名稱及完整路徑,該檔案在初始快照套用給訂閱者之前執行。

(繼承來源 Publication)
PubId

獲得唯一識別該出版品的價值。

(繼承來源 Publication)
PublisherName

取得或設定非SQL Server Publisher的名稱。

QueueType

取得或設定可用於排隊更新訂閱的出版品的佇列類型。

ReplicateDdl

取得或設定資料定義語言(DDL)的複寫選項,以判斷是否被複製DDL變更。

(繼承來源 Publication)
RetentionPeriod

當訂閱未與出版品同步時,它會取得或設定訂閱到期前的期限。

(繼承來源 Publication)
SecureFtpPassword

為登入帳號設定密碼(作為 SecureString 物件),用於連接允許透過 FTP 初始化訂閱的發佈檔案傳輸協定(FTP)伺服器。

(繼承來源 Publication)
SnapshotAgentExists

是否存在 SQL Server Agent 工作以產生本出版的初始快照。

(繼承來源 Publication)
SnapshotAvailable

查詢本出版物的快照檔案是否可供使用。

SnapshotGenerationAgentProcessSecurity

取得一個物件,設定 Windows 帳號,讓 快照集代理程式 工作執行。

(繼承來源 Publication)
SnapshotGenerationAgentPublisherSecurity

取得 快照集代理程式 用來連接 Publisher 的安全上下文。

(繼承來源 Publication)
SnapshotJobId

取得目前出版品的 快照集代理程式 工作 ID。

(繼承來源 Publication)
SnapshotMethod

取得或設定初始快照的資料檔案格式。

(繼承來源 Publication)
SnapshotSchedule

取得一個物件,設定當前發佈的 快照集代理程式 排程。

(繼承來源 Publication)
SqlServerName

取得該物件所連接的 Microsoft SQL Server 實例名稱。

(繼承來源 ReplicationObject)
Status

取得或設定出版品的狀態。

(繼承來源 Publication)
TransArticles

代表刊物中的文章。

TransSubscriptions

代表出版物的訂閱。

Type

取得或決定出版類型。

(繼承來源 Publication)
UserData

取得或設定一個物件屬性,讓使用者能將自己的資料附加到物件上。

(繼承來源 ReplicationObject)

方法

名稱 Description
BrowseSnapshotFolder(String, String)

回傳產生快照檔案的完整路徑,該地點為特定訂閱而產生。

CheckValidCreation()

檢查有效的複製建立。

(繼承來源 ReplicationObject)
CheckValidDefinition(Boolean)

指示是否檢查有效定義。

(繼承來源 Publication)
CommitPropertyChanges()

將所有快取的屬性變更語句傳送到 Microsoft SQL Server 實例。

(繼承來源 ReplicationObject)
CopySnapshot(String, String, String)

將特定訂閱的最新快照檔案複製到目標資料夾。

Create()

創造出版。

(繼承來源 Publication)
CreateSnapshotAgent()

建立 SQL Server Agent 工作,用於產生發佈的初始快照(若該工作尚未存在)。

(繼承來源 Publication)
Decouple()

將參考的複製物件與伺服器解耦。

(繼承來源 ReplicationObject)
EnumArticles()

將刊物中的文章歸還。

(繼承來源 Publication)
EnumPublicationAccesses(Boolean)

回傳有權限存取 Publisher 的登入帳號。

(繼承來源 Publication)
EnumSubscriptions()

退還訂閱該刊物的訂閱者。

(繼承來源 Publication)
GetChangeCommand(StringBuilder, String, String)

回傳複製中的變更指令。

(繼承來源 ReplicationObject)
GetCreateCommand(StringBuilder, Boolean, ScriptOptions)

回傳複製中的 create 指令。

(繼承來源 ReplicationObject)
GetDropCommand(StringBuilder, Boolean)

從複製中回傳 drop 指令。

(繼承來源 ReplicationObject)
GrantPublicationAccess(String)

將指定的登入資料加入出版存取清單(PAL)。

(繼承來源 Publication)
InternalRefresh(Boolean)

會從複製中啟動內部刷新。

(繼承來源 ReplicationObject)
Load()

從伺服器載入現有物件的屬性。

(繼承來源 ReplicationObject)
LoadProperties()

從伺服器載入現有物件的屬性。

(繼承來源 ReplicationObject)
MakePullSubscriptionWellKnown(String, String, SubscriptionSyncType, TransSubscriberType, Boolean)

代表交易性出版物。

MakePullSubscriptionWellKnown(String, String, SubscriptionSyncType, TransSubscriberType)

在 Publisher 註冊拉取訂閱。

PostTracerToken()

會將追蹤標記貼入 Publisher 日誌,開始判定延遲的過程。

Refresh()

重新載入物件的屬性。

(繼承來源 ReplicationObject)
RefreshSubscriptions()

更新所有刊物訂閱,以包含新增的文章。

ReinitializeAllSubscriptions()

標記所有訂閱本刊物的用戶進行重新初始化。

ReinitializeAllSubscriptions(Boolean)

標記所有發佈訂閱進行重新初始化,並可選擇使現有快照失效。

Remove()

移除現有出版物。

(繼承來源 Publication)
Remove(Boolean)

即使無法存取發行商,也能移除現有的出版品。

(繼承來源 Publication)
RemovePullSubscription(String, String)

移除 Publisher 的拉取訂閱註冊。

ReplicateUserDefinedScript(String)

將使用者定義腳本的執行複製給指定出版品的訂閱者。

(繼承來源 Publication)
RevokePublicationAccess(String)

將指定的登入從出版存取清單(PAL)中移除。

(繼承來源 Publication)
Script(ScriptOptions)

產生 Transact-SQL 腳本,可用來依腳本選項重製出版品。

(繼承來源 Publication)
SetPeerConflictDetection(Boolean, Int32)

啟用或停用點對點拓撲中節點的衝突偵測。

StartSnapshotGenerationAgentJob()

啟動產生發表初始快照的工作。

(繼承來源 Publication)
StopSnapshotGenerationAgentJob()

嘗試停止正在執行的 快照集代理程式 工作。

(繼承來源 Publication)
ValidatePublication(ValidationOption, ValidationMethod, Boolean)

為所有訂閱啟動內嵌發表驗證。

ValidateSubscriptions(String[], String[], ValidationOption, ValidationMethod, Boolean)

呼叫指定訂閱的內嵌發表驗證。

適用於

另請參閱