방법: 초기 스냅숏 만들기(RMO 프로그래밍)

스냅숏 에이전트는 게시가 만들어진 후 스냅숏을 생성합니다. RMO(복제 관리 개체)를 사용하여 이러한 스냅숏을 프로그래밍 방식으로 생성하고 복제 에이전트 기능에 액세스하도록 관리 코드에 지시할 수 있습니다. 사용하는 개체는 복제 유형에 따라 달라집니다. 스냅숏 에이전트는 SnapshotGenerationAgent 개체를 사용하여 동기적으로 시작하거나 에이전트 작업을 사용하여 비동기적으로 시작할 수 있습니다. 생성된 초기 스냅숏은 구독이 처음 동기화될 때 구독자로 전송되어 적용됩니다. 기존 스냅숏에 유효한 최신 데이터가 필요하게 될 때마다 에이전트를 다시 실행해야 합니다. 자세한 내용은 게시 유지 관리를 참조하십시오.

매개 변수가 있는 필터를 사용하는 병합 게시에는 두 부분으로 구성된 스냅숏이 필요합니다. 자세한 내용은 방법: 매개 변수가 있는 필터를 사용하여 병합 게시에 대한 스냅숏 만들기(RMO 프로그래밍)를 참조하십시오.

보안 정보보안 정보

가능하면 런타임에 사용자에게 자격 증명을 입력하라는 메시지를 표시하십시오. 자격 증명을 저장해야 하는 경우 Microsoft Windows .NET Framework에서 제공하는 암호화 서비스를 사용합니다.

스냅숏 에이전트 작업을 시작하여 스냅숏 또는 트랜잭션 게시에 대한 초기 스냅숏을 생성하려면(비동기)

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. TransPublication 클래스의 인스턴스를 만듭니다. 게시에 대해 NameDatabaseName 속성을 설정하고 ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.

  3. LoadProperties 메서드를 호출하여 개체의 나머지 속성을 로드합니다. 이 메서드가 false를 반환하는 경우 2단계에서 게시 속성이 올바르게 정의되지 않았거나 게시가 없는 것입니다.

  4. SnapshotAgentExists의 값이 false이면 CreateSnapshotAgent를 호출하여 이 게시에 대한 스냅숏 에이전트 작업을 만듭니다.

  5. StartSnapshotGenerationAgentJob 메서드를 호출하여 이 게시에 대한 스냅숏을 생성하는 에이전트 작업을 시작합니다.

  6. (옵션) SnapshotAvailable 값이 true이면 구독자에서 스냅숏을 사용할 수 있습니다.

스냅숏 에이전트를 실행하여 스냅숏 또는 트랜잭션 게시에 대한 초기 스냅숏을 생성하려면(동기)

  1. SnapshotGenerationAgent 클래스의 인스턴스를 만들고 다음 필수 속성을 설정합니다.

  2. ReplicationTypeTransactional 또는 Snapshot 값을 설정합니다.

  3. GenerateSnapshot 메서드를 호출합니다.

스냅숏 에이전트 작업을 시작하여 병합 게시에 대한 초기 스냅숏을 생성하려면(비동기)

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. MergePublication 클래스의 인스턴스를 만듭니다. 게시에 대해 NameDatabaseName 속성을 설정하고 ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.

  3. LoadProperties 메서드를 호출하여 개체의 나머지 속성을 로드합니다. 이 메서드가 false를 반환하는 경우 2단계에서 게시 속성이 올바르게 정의되지 않았거나 게시가 없습니다.

  4. SnapshotAgentExists의 값이 false이면 CreateSnapshotAgent를 호출하여 이 게시에 대한 스냅숏 에이전트 작업을 만듭니다.

  5. StartSnapshotGenerationAgentJob 메서드를 호출하여 이 게시에 대한 스냅숏을 생성하는 에이전트 작업을 시작합니다.

  6. (옵션) SnapshotAvailable 값이 true이면 구독자에서 스냅숏을 사용할 수 있습니다.

스냅숏 에이전트를 실행하여 병합 게시에 대한 초기 스냅숏을 생성하려면(동기)

  1. SnapshotGenerationAgent 클래스의 인스턴스를 만들고 다음 필수 속성을 설정합니다.

  2. ReplicationTypeMerge 값을 설정합니다.

  3. GenerateSnapshot 메서드를 호출합니다.

이 예에서는 스냅숏 에이전트를 동기적으로 실행하여 트랜잭션 게시에 대한 초기 스냅숏을 생성합니다.

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

            SnapshotGenerationAgent agent;

            try
            {
                // Set the required properties for Snapshot Agent.
                agent = new SnapshotGenerationAgent();
                agent.Distributor = distributorName;
                agent.DistributorSecurityMode = SecurityMode.Integrated;
                agent.Publisher = publisherName;
                agent.PublisherSecurityMode = SecurityMode.Integrated;
                agent.Publication = publicationName;
                agent.PublisherDatabase = publicationDbName;
                agent.ReplicationType = ReplicationType.Transactional;

                // Start the agent synchronously.
                agent.GenerateSnapshot();

            }
            catch (Exception ex)
            {
                // Implement custom application error handling here.
                throw new ApplicationException(String.Format(
                    "A snapshot could not be generated for the {0} publication."
                    , publicationName), ex);
            }
' Set the Publisher, publication database, and publication names.
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks"
Dim publisherName As String = publisherInstance
Dim distributorName As String = publisherInstance

Dim agent As SnapshotGenerationAgent

Try
    ' Set the required properties for Snapshot Agent.
    agent = New SnapshotGenerationAgent()
    agent.Distributor = distributorName
    agent.DistributorSecurityMode = SecurityMode.Integrated
    agent.Publisher = publisherName
    agent.PublisherSecurityMode = SecurityMode.Integrated
    agent.Publication = publicationName
    agent.PublisherDatabase = publicationDbName
    agent.ReplicationType = ReplicationType.Transactional

    ' Start the agent synchronously.
    agent.GenerateSnapshot()

Catch ex As Exception
    ' Implement custom application error handling here.
    Throw New ApplicationException(String.Format( _
     "A snapshot could not be generated for the {0} publication." _
     , publicationName), ex)
End Try

이 예에서는 에이전트 작업을 비동기적으로 시작하여 트랜잭션 게시에 대한 초기 스냅숏을 생성합니다.

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

            TransPublication publication;

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

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

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

                if (publication.LoadProperties())
                {
                    // Start the Snapshot Agent job for the publication.
                    publication.StartSnapshotGenerationAgentJob();
                }
                else
                {
                    throw new ApplicationException(String.Format(
                        "The {0} publication does not exist.", publicationName));
                }
            }
            catch (Exception ex)
            {
                // Implement custom application error handling here.
                throw new ApplicationException(String.Format(
                    "A snapshot could not be generated for the {0} publication."
                    , publicationName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Set the Publisher, publication database, and publication names.
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks"
Dim publisherName As String = publisherInstance

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()

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

    If publication.LoadProperties() Then
        ' Start the Snapshot Agent job for the publication.
        publication.StartSnapshotGenerationAgentJob()
    Else
        Throw New ApplicationException(String.Format( _
         "The {0} publication does not exist.", publicationName))
    End If
Catch ex As Exception
    ' Implement custom application error handling here.
    Throw New ApplicationException(String.Format( _
     "A snapshot could not be generated for the {0} publication." _
     , publicationName), ex)
Finally
    conn.Disconnect()
End Try