Freigeben über


Publication.StartSnapshotGenerationAgentJob Methode

Definition

Startet den Auftrag, der die Anfangsmomentaufnahme für die Veröffentlichung generiert.

public:
 void StartSnapshotGenerationAgentJob();
public void StartSnapshotGenerationAgentJob ();
member this.StartSnapshotGenerationAgentJob : unit -> unit
Public Sub StartSnapshotGenerationAgentJob ()

Ausnahmen

Auf dem Server wird microsoft SQL Server 2005 oder höher nicht ausgeführt, oder die Veröffentlichung ist auf dem Server nicht vorhanden.

Beispiele

// Set the Publisher, publication database, and publication names.
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
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 = "AdventureWorks2012"
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

Hinweise

Die StartSnapshotGenerationAgentJob -Methode kann nur von Mitgliedern der sysadmin festen Serverrolle auf dem Verleger oder von Mitgliedern der db_owner festen Datenbankrolle in der Veröffentlichungsdatenbank aufgerufen werden.

Das Aufrufen StartSnapshotGenerationAgentJob entspricht der Ausführung sp_startpublication_snapshot (Transact-SQL).

Gilt für:

Weitere Informationen