Using SharedConnectionWorkflowCommitWorkBatchService
When the runtime engine is started, the WorkflowRuntime class creates a DefaultWorkflowCommitWorkBatchService object if no other WorkflowCommitWorkBatch service has been added. You can use this service in your workflow to support work batches that are needed for data integrity.
You can also choose to use the SharedConnectionWorkflowCommitWorkBatchService service. This service is used for database transactions that use a shared connection between different objects. To use the SharedConnectionWorkflowCommitWorkBatchService service instead of the DefaultWorkflowCommitWorkBatchService service in your WorkflowRuntime instance, use the AddService method, as shown in the following example. The parameter to the SharedConnectionWorkflowCommitWorkBatchService constructor is the database connection string.
Note
If the SQL server that is being used by the SharedConnectionWorkflowCommitWorkBatchService service is down, such as that caused by SQL cluster failovers or intermittent network issues, the SharedConnectionWorkflowCommitWorkBatchService service retries the commit process at least 15 to 20 times before raising a ServicesExceptionNotHandled event. However, this behavior occurs only when the EnableRetries property of the SharedConnectionWorkflowCommitWorkBatchService service is set to true.
static void Main(string[] args)
{
string connectionString = " Initial Catalog=WorkflowDataStore;Data Source=localhost;Integrated Security=SSPI;";
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.AddService( new SharedConnectionWorkflowCommitWorkBatchService(connectionString));
workflowRuntime.StartRuntime();
// …
workflowRuntime.StopRuntime();
}
Shared Sub Main(ByVal args() As String)
Dim connectionString As String = " Initial Catalog=WorkflowDataStore;Data Source=localhost;Integrated Security=SSPI;"
Dim workflowRuntime As New WorkflowRuntime()
workflowRuntime.AddService(New SharedConnectionWorkflowCommitWorkBatchService(connectionString))
workflowRuntime.StartRuntime()
' ...
workflowRuntime.StopRuntime()
End Sub 'Main
Using an Application Configuration File
You can also use an application configuration file to create the SharedConnectionWorkflowCommitWorkBatchService object. When you do this, you add the connection string information to the CommonParameters section of the App.config file. The following example shows an application configuration file that uses the SharedConnectionWorkflowCommitWorkBatchService service.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="WorkflowServiceContainer" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<WorkflowServiceContainer Name="Container Name" UnloadOnIdle="true">
<CommonParameters>
<add name="ConnectionString" value="Initial Catalog=WorkFlowStore;Data Source=localhost;Integrated Security=SSPI;" />
</CommonParameters>
<Services>
<add type="System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService, System.Workflow.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add type="System.Workflow.Runtime.Hosting.SharedConnectionWorkflowTransactionService, System.Workflow.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</Services>
</WorkflowServiceContainer>
<system.diagnostics>
</system.diagnostics>
</configuration>
See Also
Reference
DefaultWorkflowCommitWorkBatchService
SharedConnectionWorkflowCommitWorkBatchService
Concepts
Services Overview
Windows Workflow CommitWorkBatch Services