Simple Tracking 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)); wr.StartRuntime();
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:
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
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:
CREATE DATABASE Tracking
In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.
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.
Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service tables.
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.
Execute the query by clicking Execute or by pressing F5 to create the SQL tracking service stored procedures.
To build the sample
Download the sample by clicking Download Sample.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
- 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.
Query Using SQLTrackingService Sample
Tracking Using User Track Points Sample
EventArgs Tracking Sample
Query Using SQLTrackingService Sample
File Tracking Service and Query Sample
Using the Tracking Profile Object Model Sample
SQL Data Maintenance Sample
© 2007 Microsoft Corporation. All rights reserved.