SnapshotGenerationAgent Class

Provides the functionality of the Replication Snapshot Agent.

System.Object
  System.MarshalByRefObject
    Microsoft.SqlServer.Replication.AgentCore
      Microsoft.SqlServer.Replication.SnapshotGenerationAgent

Namespace:  Microsoft.SqlServer.Replication
Assembly:  Microsoft.SqlServer.Replication (in Microsoft.SqlServer.Replication.dll)

[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[GuidAttribute("141945FD-18BD-4222-B6D9-F937704C7FFE")]
[ComVisibleAttribute(true)]
public sealed class SnapshotGenerationAgent : AgentCore, 
	ISnapshotGenerationAgent

The SnapshotGenerationAgent type exposes the following members.

  NameDescription
Public methodSnapshotGenerationAgentCreates an instance of the SnapshotGenerationAgent class.
Top

  NameDescription
Public propertyAbortPolicyGets or sets how running replication agent threads are terminated when an unanticipated shutdown occurs. (Inherited from AgentCore.)
Public propertyBcpBatchSizeGets or set the number of rows to send to the Distributor in a bulk copy operation.
Public propertyComErrorCollectionReturns information on errors that occur during agent execution. (Inherited from AgentCore.)
Public propertyDistributorGets or sets the name of the instance of SQL Server acting as the Distributor for the publication.
Public propertyDistributorDeadlockPriorityGets or sets the priority of the Snapshot Agent connection to the Distributor when a deadlock occurs.
Public propertyDistributorEncryptedPasswordInfrastructure.
Public propertyDistributorEncryptionLevelGets of sets the level of Secure Sockets Layer (SSL) encryption used by the Snapshot Agent when connecting to the Distributor.
Public propertyDistributorLoginGets or sets the login name used when connecting locally to the Distributor using SQL Server Authentication.
Public propertyDistributorNetworkLibraryInfrastructure.
Public propertyDistributorPasswordSets the password used when connecting locally to the Distributor using SQL Server Authentication.
Public propertyDistributorSecurityModeGets or sets the security mode used when connecting locally to the Distributor.
Public propertyDynamicFilterHostNameGets or sets the value supplied to the HOST_NAME function used in a parameterized row filter.
Public propertyDynamicFilterLoginGets or sets the value supplied to the SUSER_SNAME function used in a parameterized row filter.
Public propertyDynamicSnapshotLocationGets or sets the location of the partitioned snapshot for a subscription to a merge publication that is defined based-on a parameterized row filter.
Public propertyFieldDelimiterGets or sets the character or character sequence that marks the end of a field in the SQL Server bulk-copy data file.
Public propertyFlatExceptionCollectionInfrastructure. (Inherited from AgentCore.)
Public propertyHistoryVerboseLevelGets or sets the amount of history logged during agent execution. (Inherited from AgentCore.)
Public propertyHRBcpBlocksInfrastructure.
Public propertyHRBcpBlockSizeInfrastructure.
Public propertyHRBcpDynamicBlocksInfrastructure.
Public propertyLoginTimeoutGet or sets the number of seconds before the login times out for connections made by the agent. (Inherited from AgentCore.)
Public propertyMaxBcpThreadsGets or sets the number of bulk copy operations that can be performed in parallel.
Public propertyMaxNetworkOptimizationGets or sets whether out-of-partition deletes are sent to the Subscriber.
Public propertyOnetimeDynamicSnapshotInfrastructure.
Public propertyOutputGet or sets the name and path of the agent output file. (Inherited from AgentCore.)
Public propertyOutputVerboseLevelGets or sets the level of detail of information written to the agent output file. (Inherited from AgentCore.)
Public propertyPacketSizeInfrastructure. (Inherited from AgentCore.)
Public propertyProfileNameGets or sets an agent profile to use when running the agent. (Inherited from AgentCore.)
Public propertyPublicationGets or sets the name of the publication.
Public propertyPublisherGets or sets the name of the instance of SQL Server that is the Publisher.
Public propertyPublisherDatabaseGets or sets the name of the publication database.
Public propertyPublisherDeadlockPriorityGets or sets the priority of the Snapshot Agent connection to the Publisher when a deadlock occurs.
Public propertyPublisherEncryptedPasswordInfrastructure.
Public propertyPublisherEncryptionLevelGets of sets the level of Secure Sockets Layer (SSL) encryption used by the Snapshot Agent when connecting to the Distributor.
Public propertyPublisherFailoverPartnerGets or sets the failover partner instance of SQL Server participating in a database mirroring session with the publication database. (Inherited from AgentCore.)
Public propertyPublisherLoginGets or sets the login name used when connecting to the Publisher using SQL Server Authentication.
Public propertyPublisherNetworkLibraryInfrastructure.
Public propertyPublisherPasswordSets the password used when connecting to the Publisher using SQL Server Authentication.
Public propertyPublisherSecurityModeGets or sets the security mode used when connecting to the Publisher.
Public propertyQueryTimeoutGet or sets the number of seconds before a query times out. (Inherited from AgentCore.)
Public propertyReplicationTypeGets or sets the type of publication.
Public propertyRowDelimiterGets or sets the character or character sequence that marks the end of a row in the SQL Server bulk-copy data file.
Public propertySecureDistributorEncryptedPasswordInfrastructure.
Public propertySecureDistributorPasswordSets the password (as a SecureString object) used when connecting locally to the Distributor using SQL Server Authentication.
Public propertySecurePublisherEncryptedPasswordInfrastructure.
Public propertySecurePublisherPasswordSets the password (as a SecureString object) used when connecting to the Publisher using SQL Server Authentication.
Public propertyStartQueueTimeoutGets or sets the time that the Snapshot Agent waits when the maximum number of concurrent partitioned snapshot processes for a merge publication are already running.
Public propertySupports70SubscribersGets or sets whether the generated snapshot supports SQL Server 7.0 Subscribers.
Top

  NameDescription
Public methodAbort (Inherited from AgentCore.)
Public methodCreateObjRef (Inherited from MarshalByRefObject.)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGenerateSnapshotStarts the Snapshot Agent to generate the snapshot.
Public methodGetHashCode (Inherited from Object.)
Public methodGetLifetimeService (Inherited from MarshalByRefObject.)
Public methodGetType (Inherited from Object.)
Public methodInitializeLifetimeService (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone() (Inherited from Object.)
Protected methodMemberwiseClone(Boolean) (Inherited from MarshalByRefObject.)
Public methodResetParametersToDefault (Inherited from AgentCore.)
Public methodToString (Inherited from Object.)
Top

  NameDescription
Public eventComStatus (Inherited from AgentCore.)
Public eventStatusOccurs when a running agent returns status information. (Inherited from AgentCore.)
Top

The SnapshotGenerationAgent class provides direct, programmatic access to the Snapshot Agent.

The SnapshotGenerationAgent class supports the ability to do the following replication tasks:

  • Generate the initial snapshot

  • Generate a partitioned snapshot for a subscription defined based-on a parameterized filter.

This example generates a standard snapshot for a transactional publication.

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


This example generates a standard snapshot for a merge publication.

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

    // 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 = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2008R2"
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.Merge

    ' 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


This example overloads the HOST_NAME function to generate a filtered data snapshot for a subscription to a merge publication that has a parameterized filter.

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

				// Specify the partition information to generate a 
				// filtered snapshot based on Hostname.
				agent.DynamicFilterHostName = hostname;

				// 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 = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2008R2"
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.Merge

    ' Specify the partition information to generate a 
    ' filtered snapshot based on Hostname.
    agent.DynamicFilterHostName = hostname

    ' 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


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

Community Additions

ADD
Show: