Partilhar via


Setup and Enabling SqlTrackingService

Setup and Enabling SqlTrackingService

Windows Workflow Foundation offers a SQL-based out of box SQL Tracking Service. The SqlTrackingService will save the tracked data to a SQL store, provides support for per type, and per instance tracking profiles, it also comes with a set of SqlTrackingQuery APIs to query the database for some scenarios and archiving support. Check it out!

Since WF is a platform component we don’t attempt to setup and enable the SqlTrackingService by default when you install and you will need to follow simple steps to set it up and enable it. Following is how to do it. For more information on the SqlTrackingService check the Windows Workflow Foundation Help

Setup SqlTrackingService

WF provides the necessary scripts that create the schema, database objects, and the logic for the OOB SqlTrackingService. You need to create the database and use these scripts to setup the SqlTrackingService as follows:

1) Create a database Tracking

2) Run Tracking_Schema.sql and Tracking_Logic.sql located in C:\WINDOWS\WinFX\v3.0\Windows Workflow Foundation\SQL\EN against your newly created database

Enable SqlTrackingService

Similarly to any WF runtime service you can enable the SqlTrackingService via code or config file:

Via Code

Follow the steps below to enable the SqlTrackingService via code:

1) Create a connection string to your database,

2) Create an instance of SqlTrackingService and add it to WorkflowRuntime before starting WorkflowRuntime.

Your code will look as follows (assuming your database name is Tracking and it is on localhost)

private void StartCaseManagementProcess()

{

WorkflowRuntime workflowRuntime = new WorkflowRuntime();

string connectionstring =

"Initial Catalog=Tracking;DataSource=localhost;Integrated Security=SSPI;";

workflowRuntime.AddService(new SqlTrackingService(connectionstring));

WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(CaseManagementWorkflow));

workflowInstance.Start();

}

Via Config File

Follow the steps below to enable the SqlTrackingService via config file:

1) Add SqlTrackingService in Config File as follows

<WorkflowRuntime Name="ConfigSection ">

<Services>

<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

ConnectionString = "Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;"

UseDefaultProfile = "true"

IsTransactional = "true"

ProfileChangeCheckInterval = "60000"

PartitionOnCompletion = "false"

/>

</Services>

</WorkflowRuntime

2) Create WorkflowRuntime using section name before starting WorkflowRuntime – your code will look as follows

WorkflowRuntime workflowRuntime = new WorkflowRuntime("ConfigSection");