How to: Measure Latency and Validate Connections for Transactional Replication (RMO Programming)
For transactional replication, it is important to be able to verify that servers are connected and to measure latency. You measure latency by using tracer tokens. Latency is the time that elapses for changes made at the Publisher to be propagated to Subscribers. For more information, see Medir la latencia y validar las conexiones en la réplica transaccional. This information can be obtained programmatically by using Replication Management Objects (RMO).
To post a tracer token to a transactional publication
Create a connection to the Publisher by using the ServerConnection class.
Create an instance of the TransPublication class.
Set the Name and DatabaseName properties for the publication, and set the ConnectionContext property to the connection created in step 1.
Call the LoadProperties method to get the properties of the object. If this method returns false, either the publication properties in step 3 were defined incorrectly or the publication does not exist.
Call the PostTracerToken method. This method inserts a tracer token into the publication's transaction log.
To determine latency and validate connections for a transactional publication
Create a connection to the Distributor by using the ServerConnection class.
Create an instance of the PublicationMonitor class.
Set the Name, DistributionDBName, PublisherName, and PublicationDBName properties, and set the ConnectionContext property to the connection created in step 1.
Call the LoadProperties method to get the properties of the object. If this method returns false, either the publication monitor properties in step 3 were defined incorrectly or the publication does not exist.
Call the EnumTracerTokens method. Cast the returned ArrayList object to an array of TracerToken objects.
Call the EnumTracerTokenHistory method. Pass a value of TracerTokenID for a tracer token from step 5. This returns latency information for the selected tracer token as a DataSet object. If all tracer token information is returned, the connection between the Publisher and Distributor and the connection between the Distributor and the Subscriber both exist and the replication topology is functioning.
To remove tracer tokens
Create a connection to the Distributor by using the ServerConnection class.
Create an instance of the PublicationMonitor class.
Set the Name, DistributionDBName, PublisherName, and PublicationDBName properties, and set the ConnectionContext property to the connection created in step 1.
Call the LoadProperties method to get the properties of the object. If this method returns false, either the publication monitor properties in step 3 were defined incorrectly or the publication does not exist.
Call the EnumTracerTokens method. Cast the returned ArrayList object to an array of TracerToken objects.
Call the CleanUpTracerTokenHistory method. Pass one of the following values:
- The TracerTokenID for a tracer token from step 5. This deletes information for a selected token.
- A DateTime object. This deletes information for all tokens older than the specified date and time.
Vea también
Tareas
Otros recursos
Cómo medir la latencia y validar conexiones para la réplica transaccional (Monitor de réplica)