Archive

Archive for May, 2007

Persistence and Tracking together

May 23, 2007 1 comment

A reader of my workflow book recently wrote me with a question about the standard persistence and tracking services. Their question concerned how to use both of these standard services at the same time. Specifically, they wanted to know how to specify two different database connection strings in the App.config.

There’s really two separate questions there. First, how do you specify two different connection strings for the services, presumably pointing to two different databases. Second, is that how you should use these two services together?

To answer the first question, you can specify the connection string in either the CommonParameters section of the App.Config, or inline as an attribute of the service itself.

For example, here is an App.Config that provides two different database connection strings, one for each service:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="WorkflowRuntime"
    type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection,
          System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
          PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <WorkflowRuntime>
    <Services>
      <add type="System.Workflow.Runtime.Tracking.SqlTrackingService,
          System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
          PublicKeyToken=31bf3856ad364e35"
      ConnectionString="Initial Catalog=WorkflowTracking;
          Data Source=localhostSQLEXPRESS;
          Integrated Security=SSPI;" />
      <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService,
          System.Workflow.Runtime, Version=3.0.00000.0,
          Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      UnloadOnIdle="true" LoadIntervalSeconds="5"
      ConnectionString="Initial Catalog=WorkflowPersistence;
          Data Source=localhostSQLEXPRESS;
          Integrated Security=SSPI;" />
    </Services>
  </WorkflowRuntime>
</configuration>

That answers the first question. However, that’s not the recommended way to use the standard persistence and tracking services at the same time. Instead, you should use the same database for persistence and tracking. One database means one connection string. And WF provides a special service named SharedConnectionWorkflowCommitWorkBatchService that you should also load. This service is optimized for use with the standard persistence and tracking services. It uses the same database connection for both services, avoiding the use of MSDTC that would otherwise be needed.

Here’s a revised App.config that loads the special commit work batch service and uses the same database for persistence and tracking. Since a single connection string is used for both services, it is moved back to the CommonParameters section of the App.config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="WorkflowRuntime"
    type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection,
          System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
          PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <WorkflowRuntime>
    <CommonParameters>
      <add name="ConnectionString"
      value="Initial Catalog=Workflow;
          Data Source=localhostSQLEXPRESS;
          Integrated Security=SSPI;" />
    </CommonParameters>
    <Services>
      <add type="System.Workflow.Runtime.Hosting.SharedConnectionWorkflowCommitWorkBatchService,
          System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
          PublicKeyToken=31bf3856ad364e35" />
      <add type="System.Workflow.Runtime.Tracking.SqlTrackingService,
          System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
          PublicKeyToken=31bf3856ad364e35" />
      <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService,
          System.Workflow.Runtime, Version=3.0.00000.0,
          Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      UnloadOnIdle="true" LoadIntervalSeconds="5" />
    </Services>
  </WorkflowRuntime>
</configuration>
Advertisements
Categories: workflow