Not able to query Tracking data real time when application and tracking database on different machines

The remote SQL server's clock should be in sync with the machine's clock where the program is run.

The sqlTrackingWorkflowInstance.WorkflowEvents fetches WorkFlowEvents in a DateTime range between SqlDateTime.MinValue and DateTime.UtcNow. If the SQL machines clock is ahead of the application machines clock then events will not be fetched until the application machine's clock catches up with the events DateTime creation time.

CONCLUSION:

  1. Make sure your application server and Database server clock is in sync (you have to sync it to seconds also).
  2. make sure tracking service IsTransactional  property set it to false

Example:

SqlTrackingService trackingservice = new SqlTrackingService(connectionString);

trackingservice.IsTransactional = false;

workflowRuntime.AddService(trackingservice);