SnapshotGenerationAgent Class
Provides the functionality of the Replication Snapshot Agent.
Assembly: Microsoft.SqlServer.Replication (in Microsoft.SqlServer.Replication.dll)
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 = "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
This example generates a standard snapshot for a merge publication.
// Set the Publisher, publication database, and publication names. string publicationName = "AdvWorksSalesOrdersMerge"; 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.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 = "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.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 = "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.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 = "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.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
System.Object
System.MarshalByRefObject
Microsoft.SqlServer.Replication.AgentCore
Microsoft.SqlServer.Replication.SnapshotGenerationAgent
System.MarshalByRefObject
Microsoft.SqlServer.Replication.AgentCore
Microsoft.SqlServer.Replication.SnapshotGenerationAgent