locked
Share SqlWorkflowInstanceStore with many WorkflowServiceHost RRS feed

  • Question

  • I want more WorkflowServiceHost with persistence enabled, so created the following code. It works only for the first servicehost, when you call CreateHostClass second time you get the exception:

    System.Runtime.DurableInstancing.InstancePersistenceCommandException: SqlWorkflowInstanceStore does not support creating more than one lock owner concurrently. Consider setting InstanceStore.DefaultInstanceOwner to share the store among many applications.

    private SqlWorkflowInstanceStore _instanceStore;
    
    public MyHosting()
    {
      _instanceStore = new SqlWorkflowInstanceStore("ConnString");
    }
    
    public void CreateHostClass(Activity act, string address)
    {
      var svcHost = new WorkflowServiceHost(act, new Uri("net.pipe://localhost/"));
      svcHost.AddServiceEndpoint("IWorkflowHost", new NetNamedPipeBinding(), address);
      svcHost.DurableInstancingOptions.InstanceStore = _instanceStore;
      svcHost.Open();
    }
    

    I was thinking the next step would help, so added the following code in the constructor:

    var instanceHandle = _instanceStore.CreateInstanceHandle();
    var instanceView = _instanceStore.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
    _instanceStore.DefaultInstanceOwner = instanceView.InstanceOwner;
    

    After setting _instanceStore.DefaultInstanceOwner i get the same expception for creating the first WorkflowServiceHost. My host process is a WCF service on IIS i don't know if it is matter.

    What is the proper way to have a lot WorkflowServiceHost and share a common SqlWorkflowInstanceStore?

    Friday, March 4, 2011 7:52 AM

Answers

  • Hi,

    Please consider creating a new SqlWorkflowInstanceStore instance for a new WorkflowServiceHost instance.

    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by xeondev Thursday, March 31, 2011 11:56 AM
    Tuesday, March 8, 2011 2:04 AM

All replies

  • Hi,

    Please consider creating a new SqlWorkflowInstanceStore instance for a new WorkflowServiceHost instance.

    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by xeondev Thursday, March 31, 2011 11:56 AM
    Tuesday, March 8, 2011 2:04 AM
  • Is there any drawback related to performace / connection related things with many SqlWorkflowInstanceStore instances?
    Thursday, March 10, 2011 4:25 PM
  • Hi,

    Of cause, too many SqlWorkflowInstanceStore will consume a lot of memory. it is like database connection as we did in asp.net. you may want to consider creating a SqlWorkflowInstanceStore object pool if you have a lot of workflow service run simultaneously, so that you can reuse the instances.

    You can also try hosting these workflows in IIS/Appfabric directly, then no need to worry about this connection pool thing anymore.

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Friday, March 11, 2011 1:39 AM
  • Hi Andrew,

    Self hosted version is for development/debug purposes, prod version is planned with IIS / Appfabric so 
    probably won't be this a problem.

    But i have ended up with a different issue:
    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/d9b15f1e-2fc6-4fb4-bc64-cf8341917d06

    I can't decide this thread related to that one or not.

    Thanks
    Xeon

    Friday, March 11, 2011 8:20 AM