Simple Tracking Sample

Download sample

This sample illustrates the use of the SQL tracking service that is provided by Windows Workflow Foundation to track the execution of a workflow.

The workflow runtime raises certain events while it is executing a workflow. The tracking service can catch these events and store information about them in a SQL Server database that can be queried.

The workflow runtime raises the following types of events:

  • Instance-level events. These events are raised when a workflow instance enters into a particular state. For example, an event is raised when the workflow instance is initialized or when the workflow instance is executing.

  • Activity-level events. A workflow consists of activities, and each activity follows a life cycle. During its life cycle, the activity passes through multiple states. An event is raised when an activity reaches a particular state.

  • User-tracked events. A workflow author can create custom tracking events and add them to the code-beside of the workflow.

Data from the workflow data context can be emitted and given to the tracking service together with the events.

When you are tracking a workflow, you might not be interested in all events for all states and activities. You can create a tracking profile to specify the events and data that you are interested in. The SQL tracking service has a default tracking profile. This example demonstrates how to use the SQL tracking service with the default tracking profile.

Use the following code to register a tracking service with the workflow runtime:

WorkflowRuntime wr = new WorkflowRuntime();
wr.AddService(new SqlTrackingService(connectionstring));

The second line registers the SQL tracking service with the workflow runtime. The connection string is the connection string of the tracking database.

The output of the sample will appear as follows:

Simple Tracking Sample Output

Creating the Tracking Database

The SQL services that are installed by Windows Workflow Foundation use Microsoft SQL Server to store information. You can use Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or Microsoft SQL Server 2000 Desktop Engine (MSDE) for these tasks.

Windows Workflow Foundation Setup does not install the databases that are required by these services; however, Setup installs the SQL scripts for creating and configuring the databases for these services.

To create the SQL tracking database

  1. Using Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE), create a new database named Tracking by using the SQL query statement:



When using both the SqlTrackingService and the SqlWorkflowPersistenceService in a workflow application, it is recommended that you use a single database for both persistence and tracking.

  1. In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.

  2. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Schema.sql.

  3. Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service tables.

  4. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Logic.sql.

  5. Execute the query by clicking Execute or by pressing F5 to create the SQL tracking service stored procedures.

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the SimpleTrackingSample\bin\debug folder (or the SimpleTrackingSample\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.

See Also



Other Resources

Tracking Samples
Query Using SQLTrackingService Sample
Tracking Using User Track Points Sample
EventArgs Tracking Sample
ConsoleTrackingService Sample
Query Using SQLTrackingService Sample
RuleActionTrackingEvent Sample
File Tracking Service and Query Sample
Using the Tracking Profile Object Model Sample
SQL Data Maintenance Sample

© 2007 Microsoft Corporation. All rights reserved.