SqlWorkflowPersistenceService Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Note: This API is now obsolete.

Represents a persistence service that uses a SQL database to store workflow state information.

Namespace:   System.Workflow.Runtime.Hosting
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

[ObsoleteAttribute("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
public class SqlWorkflowPersistenceService : WorkflowPersistenceService, 


Initializes a new instance of the SqlWorkflowPersistenceService class by using the specified parameters.


Initializes a new instance of the SqlWorkflowPersistenceService class by using the database connection string.

System_CAPS_pubmethodSqlWorkflowPersistenceService(String, Boolean, TimeSpan, TimeSpan)

Initializes a new instance of the SqlWorkflowPersistenceService class using a database connection string and other parameters.


Gets and sets a value that specifies whether the SqlWorkflowPersistenceService retries committing a work batch.


Gets the length of the loading interval.


Gets the WorkflowRuntime for this service.(Inherited from WorkflowRuntimeService.)


Gets the service instance identifier.


Gets the state of the WorkflowRuntimeService.(Inherited from WorkflowRuntimeService.)


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Retrieves instance descriptions of all persisted workflows.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodLoadCompletedContextActivity(Guid, Activity)

Retrieves the specified completed scope from the database.(Overrides WorkflowPersistenceService.LoadCompletedContextActivity(Guid, Activity).)


Retrieves a list of ids for workflows with expired timers.


Retrieves the specified workflow instance state from the database.(Overrides WorkflowPersistenceService.LoadWorkflowInstanceState(Guid).)


Creates a shallow copy of the current Object.(Inherited from Object.)


Starts a new timer and recovers running workflow instances.(Overrides WorkflowRuntimeService.OnStarted().)


When overridden in a derived class, represents the method that will be called when the workflow runtime engine raises the WorkflowRuntime.Stopped event.(Inherited from WorkflowRuntimeService.)

System_CAPS_protmethodRaiseServicesExceptionNotHandledEvent(Exception, Guid)

Saves the state of the specified completed scope.(Overrides WorkflowPersistenceService.SaveCompletedContextActivity(Activity).)

System_CAPS_protmethodSaveWorkflowInstanceState(Activity, Boolean)

Saves the specified workflow instance state.(Overrides WorkflowPersistenceService.SaveWorkflowInstanceState(Activity, Boolean).)


Starts the SqlWorkflowPersistenceService.(Overrides WorkflowRuntimeService.Start().)


Stops the service and the timer. (Overrides WorkflowRuntimeService.Stop().)


Returns a string that represents the current object.(Inherited from Object.)


Returns a value that indicates whether the workflow is unloaded when it is in an idle state.(Overrides WorkflowPersistenceService.UnloadOnIdle(Activity).)


Unlocks access to the specified workflow instance state.(Overrides WorkflowPersistenceService.UnlockWorkflowInstanceState(Activity).)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIPendingWork.Commit(Transaction, ICollection)

Writes an ICollection of serialized state objects to the database.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIPendingWork.Complete(Boolean, ICollection)

Completes the work batch and releases any resources.


Returns a value that indicates whether the collection of serialized state objects should be written to the database.


This material discusses types and namespaces that are obsolete. For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

The SqlWorkflowPersistenceService class represents a fully-functional persistence service. You can use this service out-of-box to persist and retrieve workflow state information about a workflow instance when requested to by the workflow runtime engine.

The SqlWorkflowPersistenceService participates in the workflow transaction batching functionality provided by the WorkflowCommitWorkBatchService. That is, it adds objects that represent pending writes to the SQL database to the WorkBatch and implements the IPendingWork interface.

The SqlWorkflowPersistenceService supports locking of workflow instances. This feature is used when several workflow runtimes share the same database. A column in the SQL database table is used to mark a workflow instance as locked whenever it is being used by a workflow runtime. The SqlWorkflowPersistenceService does not load a workflow instance that is marked as "in use" by another runtime. Typically these locks are released when the workflow instance is persisted, for example, on idle, completion, or termination. The locks can also be released automatically after a period of inactivity. This period of inactivity can be set using the constructor of the SqlWorkflowPersistenceService class. It can also be set through the configuration file.

For more information about persistence services in general, see the WorkflowPersistenceService class.

Workflow instances can contain timers, for example, if they have a DelayActivity. For workflows that contain timers, the SqlWorkflowPersistenceService records the time when the workflow's next timer expires. The SqlWorkflowPersistenceService periodically polls the database, looking for workflows whose timers have expired. The frequency of the polling interval can be set using the SqlWorkflowPersistenceService constructor or using a configuration file.


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

.NET Framework
Available since 3.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top