The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename



14-5-2008 11:51:139-4-2008 19:32:269-4-2008 19:31:58

List all versions

Sql Ce Workflow Persistence Service

One of the main advantages is ClickOnce deployment. In the case of the standard SqlWorkflowPersistenceService you need to have SQL Server installed and running and create the database, with a name of your choosing, using two scripts. Not a big problem but something that needs to be done first and is outside of the realm of what you would like to do with ClickOnce. Not so with SQL Server Compact. No with SqlCe you can just deploy a number of DLL's with your application and you are ready to go, so much easier and very ClickOnce compatible [] Add easy installation is just what you want when you are creating sample applications.

I actually did all the data access using LINQ to SQL which fully supports SqlCe as a client. It might appear not to as there is no designer support like with SQL Server itself but runtime it works just fine []. using LINQ to SQL actually made the data access very easy and has an additional benefit, if you want to use the full SQL Server all you need to do is provide a different database connections string. One additional benefit of using LINQ to SQL was that is can check if the database exists and, if not, create it with a single function call. No need to mess with those tedious Create Table statements in SQL scripts!

Imports TheProblemSolver.Workflow.Hosting.Persistence

Module Module1
    Class Program
        Shared Sub Main()
            Using workflowRuntime As New WorkflowRuntime()

                Dim connectionStr As String = "Data Source=WorkflowPersistenceDatabase.sdf"
                Dim unloadOnIdle As Boolean = True
                Dim loadingInterval As TimeSpan = TimeSpan.FromSeconds(15)
                Dim persistence As New SqlCeWorkflowPersistenceService(connectionStr, _
                                                                       unloadOnIdle, _

                Dim workflowInstance As WorkflowInstance
                workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1))

                Console.WriteLine("Press enter to stop...")
            End Using
        End Sub
    End Class
End Module

Usage is real simple and pretty much the same as the standard SqlWorkflowPersistenceService type. The only extra is to set a reference to the TheProblemSolver.Workflow.Hosting.Persistence.dll that includes the SqlCeWorkflowPersistenceService type.

using System;
using System.Workflow.Runtime;
using TheProblemSolver.Workflow.Hosting.Persistence;

namespace TestClient
    class Program
        static void Main(string[] args)
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                string connectionStr = @"Data Source=WorkflowPersistenceDatabase.sdf";
                bool unloadOnIdle = true;
                TimeSpan loadingInterval = TimeSpan.FromSeconds(15);
                SqlCeWorkflowPersistenceService persistence = 
                    new SqlCeWorkflowPersistenceService(connectionStr, unloadOnIdle, loadingInterval);

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow1));

                Console.WriteLine("Press enter to stop...");

If you want to download the SqlCeWorkflowPersistenceService you can find it here

Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics