Forcibly Deleting a Windows Workflow

908 views Asked by At

I have a rather large Windows Workflow implementation and I sometimes have to update a workflow. Every now and then we get a situation where a workflow's definition is broken an, as a result, get the IndexOutOfRangeException thrown. This would not be a problem if WF would allow you to terminate the workflow using the Terminate() or Abort() methods.

There are two solution that I am aware of. The first involves removing and adding the Workflow tables using the .SQL script Microsoft wrote. The other is to modify the definition and save it back to the percistant tables - this is a very tedious task and not recommended for the faint of heart.

I want to know if there is a third option that perhaps people are afraid to consider - deleting the records from the dbo.InstanceState and dbo.WorkflowInstance tables. Below is a script that will do the trick:

DECLARE @WorkflowInstancID uniqueidentifier
-- SET @WorkflowInstancID = <Your friendly, offending Workflow Instance ID>
DELETE FROM dbo.WorkflowInstanceEvent
    WHERE WorkflowInstanceInternalId IN (SELECT WorkflowInstanceInternalId FROM dbo.WorkflowInstance WHERE WorkflowInstanceId = @WorkflowInstancID)
DELETE FROM dbo.UserEvent
    WHERE WorkflowInstanceInternalId IN (SELECT WorkflowInstanceInternalId FROM dbo.WorkflowInstance WHERE WorkflowInstanceId = @WorkflowInstancID)
DELETE FROM dbo.ActivityInstance
    WHERE WorkflowInstanceInternalId IN (SELECT WorkflowInstanceInternalId FROM dbo.WorkflowInstance WHERE WorkflowInstanceId = @WorkflowInstancID)
DELETE FROM dbo.ActivityExecutionStatusEvent
    WHERE WorkflowInstanceInternalId IN (SELECT WorkflowInstanceInternalId FROM dbo.WorkflowInstance WHERE WorkflowInstanceId = @WorkflowInstancID)
DELETE FROM dbo.InstanceState WHERE uidInstanceID = @WorkflowInstancID
DELETE FROM dbo.WorkflowInstance WHERE WorkflowInstanceId = @WorkflowInstancID
GO

This simple script works in my case. I just wanted to pose it to the community to hear any pros or cons to this approach.

1

There are 1 answers

0
Maurice On

There is no problem with doing this. In fact AppFabric has a menu option for exactly this purpose. I never checked but I presume it executes a PowerShell command, most menu options do, and you could do the same action using the PS command.