views:

504

answers:

2

I'm running a workflow runtime that contains an SqlWorkflowPersistenceService & SqlTrackingService (with IsTransactional = true)

WorkflowInstance workflowInstance = _workflowRuntime.CreateWorkflow(workflowType);
workflowInstance.Start();

// Assure persistence
workflowInstance.Unload(); // Error occur here
workflowInstance.Load();

The error I'm getting is:

PersistenceException "Cannot access a disposed object.\r\nObject name: 'Transaction'."
   at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)
   at System.Workflow.Runtime.WorkflowExecutor.PerformUnloading(Boolean handleExceptions)
   at System.Workflow.Runtime.WorkflowExecutor.Unload()
   at System.Workflow.Runtime.WorkflowInstance.Unload()

Everything works fine if i'm not adding the SqlTrackingService or setting it's "IsTransactional" to true


Edit: This error occur only when using a remote database. The exact same code will work if executing it from the database computer.

A: 

I have not seen this error before but something that may help in debugging this is the IsTransactional setting. This name is a bit misleading and really means batch updates to tyhe database until a persistence point is reached. When the UnLoad() is called this is a persistence point and with IsTransactional = true all tracking records will be persisted. When IsTransactional = false they are persisted as soon as they are created.

Something that might be involved is the DTC. Even if you are using the same database fro tracking and persistence multiple connections will be opened resulting in a distributed transaction unless you are using the SharedConnectionWorkflowCommitWorkBatchService.

Maurice
HuBeZa
+1  A: 

Problem solved.

SharedConnectionWorkflowCommitWorkBatchService wasn't the answer. Using it was only a partial solution because:

  1. It will work only if both of your persistence & tracking services are on the same database.
  2. You won't be able to promote a transaction within a transaction (for instance, update your database records during a transaction scope). It will throw an exception.


The real problem - DTC was disabled
Starting from Windows XP SP2, network access for MSDTC (Microsoft Distributed Transaction Coordinator) is disabled by default.

How to fix it - enable network access for MSDTC:

  1. Start Menu -> Programs -> Administrative Tools -> Component Services
  2. Console Root -> Component Services -> Computers -> My Computer -> right click it and select Properties.
  3. Choose MSDTC, and click Security Configuration.
  4. Enable “Network DTC Access”, “Allow Remote Clients”, “Allow Remote Administration”, “Allow Inbound”, “Allow Outbound”, “Enable TIP Transactions” and “Enable XA Transactions”.
  5. Confirm all changes and close the window.
  6. If you run the Windows Firewall then you should open an exception for the MSDTC. Go to “Control Panel” -> “Security Center” -> “Windows Firewall” -> “Exceptions” -> “Add Program” -> “Browse” and select “C:\WINDOWS\system32\msdtc.exe”. Confirm all changes.
HuBeZa