Publication.StartSnapshotGenerationAgentJob Method

Starts the job that generates the initial snapshot for the publication.

네임스페이스: Microsoft.SqlServer.Replication
어셈블리: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)

구문

‘선언
Public Sub StartSnapshotGenerationAgentJob
public void StartSnapshotGenerationAgentJob ()
public:
void StartSnapshotGenerationAgentJob ()
public void StartSnapshotGenerationAgentJob ()
public function StartSnapshotGenerationAgentJob ()

예외

예외 유형 상태
ApplicationException

The server is not running Microsoft SQL Server 2005 or later, or the publication does not exist on the server.

주의

The StartSnapshotGenerationAgentJob method can only be called by members of the sysadmin fixed server role at the Publisher or by members of the db_owner fixed database role on the publication database.

Calling StartSnapshotGenerationAgentJob is equivalent to executing sp_startpublication_snapshot(Transact-SQL).

The StartSnapshotGenerationAgentJob method is available only with SQL Server 2005 and later.

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

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

스레드 보안

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

플랫폼

개발 플랫폼

지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.

대상 플랫폼

지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.

참고 항목

참조

Publication Class
Publication Members
Microsoft.SqlServer.Replication Namespace

관련 자료

How to: Create the Initial Snapshot (RMO Programming)