2013-05-19 33 views
2

我有一個windows服務,運行工作流程。工作流程是從數據庫加載的XAML(用戶可以使用rehosted設計器定義自己的工作流程)。它配置了一個SQLWorkflowInstanceStore實例,以在空閒時保持工作流程。 (它基本上來自Microsoft的WCF/WF示例的\ ControllingWorkflowApplications中的示例代碼)。WF4 InstancePersistenceCommand中斷

但有時會出現錯誤象下面這樣:

System.Runtime.DurableInstancing.InstanceOwnerException:一個InstancePersistenceCommand的執行被中斷,因爲所有者ID「a426269a-be53-44e1-8580-4d0c396842e8實例所有者註冊'已經失效了。此錯誤表示由此所有者鎖定的所有實例的內存中副本已過時,應與InstanceHandles一起丟棄。通常,最好通過重新啓動主機來處理此錯誤。

我一直在試圖找到原因,但它很難在開發中重現,但在生產服務器上,我偶爾會得到它。我發現的一個提示是:當我查看LockOwnersTable時,發現LockOnwersTable lockexpiration設置爲01/01/2000 0:0:0,並且不再更新,而在正常情況下,應該每隔x秒更新一次主機鎖更新期...

那麼,爲什麼要SQLWorkflowInstanceStore停止更新此LockExpiration,我該如何檢測它的原因呢?

回答

0

你必須肯定擁有用戶的

這裏我是怎麼來處理這個問題

 public SqlWorkflowInstanceStore SetupSqlpersistenceStore() 
    { 
     SqlWorkflowInstanceStore sqlWFInstanceStore = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["DB_WWFConnectionString"].ConnectionString); 
     sqlWFInstanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; 
     InstanceHandle handle = sqlWFInstanceStore.CreateInstanceHandle(); 
     InstanceView view = sqlWFInstanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); 
     handle.Free(); 
     sqlWFInstanceStore.DefaultInstanceOwner = view.InstanceOwner; 
     return sqlWFInstanceStore; 
    } 

,在這裏你可以如何使用此方法

 wfApp.InstanceStore = SetupSqlpersistenceStore(); 

願望到期這個幫助

+0

剛請嘗試從基本文件夾中的Microsoft WF示例中獲取示例ControllingWorkflowApplications。啓動一個Parallel1.xaml(包含在示例中)。然後停止sql server服務至少30秒。重新啓動sql server並嘗試恢復書籤,它會中止工作流程... – rekna

+0

@rekna - 我們遇到同樣的問題 - 您是否曾經找到過解決方案? –

+1

不幸的是沒有......我有一個MS開放的案例,但在這一刻,我沒有收到他們的回覆。我正在使用一種解決方法(從完美的角度來看),它監視工作流數據庫以確定鎖定吸入是否仍然有效,如果不是,則重新啓動工作流實例。我真的不明白它背後的邏輯。我希望我可以編寫一個自定義實例存儲,但MS使它變得複雜。實際上不可能從現有的實例商店中派生出來。 – rekna

1

發生這種情況是因爲有程序在後臺運行d試圖每30秒延長一次實例存儲的鎖定,並且似乎一旦連接失敗連接到SQL服務,它就會將此實例存儲標記爲無效。 如果從[LockOwnersTable]表中刪除實例存儲記錄,則可以看到相同的行爲。 提出的解決方案是,當此異常火災,你需要釋放舊實例存儲和初始化一個新

public class WorkflowInstanceStore : IWorkflowInstanceStore, IDisposable 
{ 
    public WorkflowInstanceStore(string connectionString) 
    { 
     _instanceStore = new SqlWorkflowInstanceStore(connectionString); 

     InstanceHandle handle = _instanceStore.CreateInstanceHandle(); 
     InstanceView view = _instanceStore.Execute(handle, 
      new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); 
     handle.Free(); 

     _instanceStore.DefaultInstanceOwner = view.InstanceOwner; 
    } 

    public InstanceStore Store 
    { 
     get { return _instanceStore; } 
    } 

    public void Dispose() 
    { 
     if (null != _instanceStore) 
     { 
      var deleteOwner = new DeleteWorkflowOwnerCommand(); 
      InstanceHandle handle = _instanceStore.CreateInstanceHandle(); 
      _instanceStore.Execute(handle, deleteOwner, TimeSpan.FromSeconds(10)); 
      handle.Free(); 
     } 
    } 

    private InstanceStore _instanceStore; 
} 

你能找到的最佳實踐此鏈接創建實例存儲手柄 Workflow Instance Store Best practices