Home » Sharepoint 2010

Clean-up job to remove orphaned workflows?

Does SP 2010 have any kind of clean-up job that will remove associated workflows 'in progress' from a list or library on an item that has been deleted?  We had no way to remove these 'orphans' in MOSS 2007 without writing custom code.




5 Answers Found


Answer 1

Create a SPD list workflow associated with a document library. The workflow has two actions: Assign a to-do item and then pause for 2 days;

Manually start the workflow for a document item in the library, and the task item is created in Task list;

Delete the document item;

The task is still there and the task status is still Not Started;

Edit the task, and click the complete task button, error will occur saying that the document associated with the workflow is not there:


The workflow's parent item associated with this task is currently in the recycle bin, which prevents the task from being completed.

Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.

Troubleshoot issues with Microsoft SharePoint Foundation.

I deleted the document from the recycle bin (in two stage), the task disappeared. And I guess the orphaned workflow is also cleared.



Answer 2

I do not believe that deleting a document will automatically delete a workflow running on it.  Of course, there is no way to 'prove' that because since the document is not there, you can't get to the status page to see if the workflow is still in progress.  But am pretty sure that unless you terminate a workflow manually or thru the 'Stop workflow' action, it still remains in progress.

My scenario is:

Form1 is submitted to FormLibrary1 Workflow 1 begins on Form1 Workflow 1 creates Item1 in List1 (associated to Form1 via unique key) Workflow 2 begins on Item1 Based on conditions, Workflow2 deletes Form1 Workflow 2 ends Workflow 1 is now an orphaned workflow because its associated Form1 has been deleted but it remains 'in progress'



Answer 3

I am not saying that delete a document library item will also delete the workflow instance associated with it. But remove the deleted document item from site collection recycle bin (the second stage one) will permanently remove the document item as well as the workflow instance associated with it.


I had proved it by querying the Workflow table in the content database:

First, you can get the workflow instance id from the URL of the workflow status page.

Then you can find the record corresponding to the workflow instance in the Workflow table in the content database.

You can see that after delete the document, delete it in the user recycle bin and delete it in the site collection recycle bin, that piece of record in Workflow table is gone.


Note that query into the content database in SharePoint production environment is not supported, please do it in testing environment.



Answer 4

Thank you GuYuming.  Since you have already tested this out, I will accept that the 'orphan workflow' will be deleted 60 days from when the document is initially deleted by the 1st workflow (30 days in user recycle bin, after which it is auto-moved to the site collection recycle bin and auto-deleted from there 30 days later).

Answer 5


the proposed answer solves the job, but is not always feasible or possible. I might have hundreds of lists and libraries in my SharePoint environment and hence I would have to attach the event receiver to each and every list- which is quite impossible to keep track of. Furthermore, items might be moved from one list to another by a custom application which might cause the same problem.

Hence, there must be a way of getting rid of these orphaned workflow instances in the sharepoint database.

Any ideas (even with custom code) on how to achive that?




I have read quite some posts about orphaned workflows, but none of them could answer my question. We also have orphaned workflows (checked workflow table in the dev environment) that are actually no longer active on the document. Some of the documents have been moved to another location and hence I believe the orphaned workflow instances have arisen from that movement. 

Now, the question is (even if it requires custom coding) - how do I get rid of the orphaned workflows? They are residing in the workflow table and they are growing. Additionally, we have some clean up jobs running (clear history list entries, for example, to avoid "overpopulation"). With a lot of orphaned workflows, this is time consuming - over and over again.

Now, what are the possibilities? I cannot delete the respective documents on which the workflows are running.

Thanks for helping.



How to remove orphaned workflow instances in SP 2010? I dont prefer manual deletion as mentioned in below link:


 Scenario: If 2 WFs running on the same item & one WF delete the item from list while other wf is in-progress..

I referred following link :

http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/2b763502-cb4e-4715-9b1d-d0f2639d2bfe/ for MOSS.

is it applicable for SP 2010? After 60 days will it be deleted?

Please suggest me if any other solution is available.



I’ve been doing some testing with SSRS Subscriptions and I’ve noticed that the Notification Table seems to get populated and somehow, orphan items get left behing and never cleaned up.  I’ve watched it for about 24 hours and it's amazing just to see 52 rows sitting there. 


another problem is the Retry Attempt is now at 54.  Even though in the RS Configuration File - all of the retry settings say 3.


What I’ve done during a 2 hour period

Set up a SSRS Subscription to run every 1 minute and another one every 3 minutes using a custom delivery extension that takes a report, saves file, zips file and uploads to sharepoint.  This works great.

However, while testing the DLL, I had to stop and restart the SSRS service - while I do some configuration changes, or copy a new DLL - these I've been doing every 10+ minutes to tweak various settings in my custom delivery extension DLL.

Meanwhile, my report subscription is scheduled every 3 minutes. Since SQL Agent runs those, i keep accumulating a new entry in the Notification Table every 3 minutes.


Now the question is - why is my Notification Table not being cleaned up?  I thought - maybe it will get cleaned later today so I left it running... but it's now 24 hours and those 52 rows have stayed there.


I've noticed that the “ProcessAfter” column now has a date/time from the past so I don't think these subscriptions will ever run.  There are no errors in the log file.  And yet the ProcessStart column has a current timestamp and the Attempt # keeps growing. 


Do you know if this is a bug, or if SSRS will eventually come back and clean them up? Ami reading it wrong? Does SSRS insert a row in these table for all the subscriptions to be run?


Sample Output:


ProcessStartNotificationEnteredProcessAfterAttempt SubscriptionLastRunTime
1/4/11 8:48 PM1/3/11 7:17 PM1/3/11 8:08 PM541/3/11 8:17 PM
1/4/11 8:48 PM1/3/11 7:18 PM1/3/11 8:13 PM541/3/11 8:18 PM
1/4/11 8:48 PM1/3/11 7:21 PM1/3/11 8:13 PM541/3/11 8:21 PM
1/4/11 8:48 PM1/3/11 7:25 PM1/3/11 8:13 PM541/3/11 8:25 PM
1/4/11 8:48 PM1/3/11 7:27 PM1/3/11 8:13 PM541/3/11 8:27 PM
1/4/11 8:48 PM1/3/11 7:48 PM1/3/11 8:18 PM541/3/11 8:48 PM


I am working in a test environment with Project Server 2010 and SharePoint 2010. While running through disaster recovery scenarios I came across trying to delete a Projet Server Service Application where the 5 DB's were "lost". When I manage the Service Application it shows no PWA sites. However, when I go to delete the Service Application I receive the error "Service application cannot be deleted due to existing project sites". I also get this when trying to delete the Service App using the Remove-SPServiceApplication. I've tried the -removedata option with the cmdlet without any luck either.

I also tried uninstalling Project Server from the Application Server and reinstalling it after but the orphaned Service App comes back after it has been reinstalled.

How can I go about removing this Service Application?


I am seeing Event ID 17060 for MSSQLSERVER.  The server is in a two node SQL 2005 cluster. Description is "Invalid object name 'xxx.mine006.results_cluster'.  rs_sp_analysis_ETL_extractDimLeaf:exec.

I believe it is something that a team member was testing and this error is logged every minute on the active node.

I have very little SQL exp and need to see how to find this item and how to stop this error.

Should site collection user profiles 'not' found in the SSP (because they were removed during a daily sync against the AD, for example) automatically be removed?  If not, is there some sort of command line tool I could schedule to run daily to ensure user profiles in site collections which no longer exist in the SSP are removed from said site collections?
Okay, we had a user that was removed from the systems with a ID of 100. the person was added back and now has the ID of 241. The issue is that any files or post etc that had to do with this person are now orphaned. I am wondering is there a way to change the person back to the old ID of 100? I know in the user information list that would be the ID auto column. I guess another option is would there be a way to change the persons files to point to the new user ID of 241? This SharePoint install resides on a remote server to which I have no terminal services access etc. So is there a way to do this via the SharePoint portal itself? I do have administration rights etc.

I know that each list has records for users and that there is a lookup ID attached to the front of person field that looks like this 32;#Jack Smith. Of course this is all stored directly in the SQL server database so not sure how you can either change the 100;# lookups on the orphaned files to 241 or the faster one by the person ID back to 100.

anyone have an suggestions?

I have a PWA site that is not listing in the Project Server Service Application, but it still exists somewhere in the SharePoint Config.  I thought these two weren't married as tightly anymore but seems they very much are :(

What happened was deleting of the web application the PWA site was provisioned on and then re-created it.  PWA site is gone from the SA, timerjobs are still going against it seems.  Can't access the PWA site at all, even system account and PWA provisioned admin.  Remove the content DB with the PWA site and still nothing.

Tried recreating the PWA site with the same DBs and get the following error - "The database specified is already used by another project server."

Tried deleting the Service Application and get the following error - "Service application cannot be deleted due to existing project sites"



I have inherited some databases that have old SQL Server 6.5 aliases in them.  The databases had already been transferred to SQL 2000 when I took over (how they were moved from 6.5 to 2000, I don't know).  So, they have these aliases in them, that is, I get rows from this query:

select * from dbo.sysusers
where isaliased = 1

On row in particular is:

uid  status name      sid                
------ ------ -------------- -----------------------------------
5   16   \aDalton    0x81345DC7C969F84DA2E1C7852DFF48D9 

Now I am working on upgrading these servers to SQL 2008 R2, and I am trying to get rid of them.  I found another thread (http://social.msdn.microsoft.com/Forums/en-US/sqlsecurity/thread/a3aa00be-b813-465d-8b55-6b0a45dd13e7) that pointed me to the [sp_dropalias] system stored procedure.  However, that proc will not work for me, as the proc takes a login as the input, and the associated logins are long gone from my systems!

So created a login with a sid from the query above.

create login [Dalton]
 with password = 'asdfASDF1234',
 sid = 0x81345DC7C969F84DA2E1C7852DFF48D9

Then I tried...

sp_dropalias 'Dalton'

which gave me the error message "Msg 15134, Level 16, State 1, Procedure sp_dropalias, Line 36 No alias exists for the specified user." So I figured I might need a user for login as well as the alias, so I tried this:

createuser [DaltonXXX] for login [Dalton]

which gave me the error message "Msg 15022, Level 16, State 1, Line 2 The specified user name is already aliased."  Arrgh!!!

Does anyone know how to get rid of these aliases in SQL 2000 or SQL 2008?



I've got a scenario where on item creation, I start a workflow and pause for some time before resuming it.  If the item is deleted, I would like the workflow to cancel automatically, without having to to to List Settings/Worflow Settings to terminate them manually.  I know that a workflow can have the "Orphaned" status and I wouldn't mind adding a condition in my worflow that would be a bit like : "after pausing, if status = orphaned then stop workflow".  However, I can't seem to access that status in an SPD workflow...

Ideas ?


I am having a weird issue with the profile database/import.

We are on a MOSS 2007 SP2 farm.    My import is working fine.    But when someone gets disabled in AD they get added to Profiles Missing from Import.  Which is fine but then if the user gets re-enabled (which happens when doing transfers) they lose all their profile information.  Currently we are not using MySites but leveraging the personal features.    I know there is a My Site Profile Cleanup Job which deletes all id's that are in Profiles Missing from Import.   So 2 questions I am looking for:

Can I modify the My Site Profile Clean up job to run monthly or weekly?  

And if a user has been added to Profile Missing from Import (disabled My Site Profile Cleanup Job) but have been activated without getting deleted they are not being moved back to Active Profiles.  

I am trying to figure out why active users are stuck in Profiles Missing from Import.  

Any help is appreciated?


I ran the stored procedure sp_change_users_login to fix my orphan user problem that resulted from importing a new db to a server it wasn't previously on. (It is the classic problem where my user who has always been a valid user in that database cannot log in to it on the new server even though the login exists on the new server.) But when I run  execsp_change_users_login@action='Report' it still shows the same user is an orphan even though that user can log in to the database on the new server (ie problem fixed). Why does it still show him as an orphan user? And if I had used ALTER USER to fix the orphan row problem would it NOT show up when I run  execsp_change_users_login@action='Report' ?

The version I am using: Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: )

I have already read this: http://msdn.microsoft.com/en-us/library/ms176060.aspx  and this: http://msdn.microsoft.com/en-us/library/ms174378.aspx and this: http://msdn.microsoft.com/en-us/library/ms175475.aspx but they do not answer my question.

To be precise, this is what I ran which fixed my orphan user problem and allowed MyUser to login/connect to the proper database:



sp_change_users_login@Action='update_one',@UserNamePattern='MyUser', @LoginName='MyUser'


Report Server 10.0.2531.0



We’ve been using SSRS for more than 1 year now. Number of the reports and subscriptions were gradually increasing. Recently I started to see the following errors in the SQL Server Agent Error Logs:


12/20/2010 09:32:07,,Error,[000] Refresh of schedule 98106 failed because the parent job (0xB26B51B567B16C45940C9AA7132F8A85) was not found in the job cache

12/20/2010 09:32:07,,Error,[000] Failed to retrieve job 0xB26B51B567B16C45940C9AA7132F8A85 from the server

12/20/2010 09:32:07,,Error,[298] SQLServer Error: 3621<c/> The statement has been terminated. [SQLSTATE 01000]

12/20/2010 09:32:07,,Error,[298] SQLServer Error: 2601<c/> Cannot insert duplicate key row in object 'dbo.sysjobactivity' with unique index 'clust'. [SQLSTATE 23000]

12/20/2010 09:32:07,,Warning,[156] Job 0xB26B51B567B16C45940C9AA7132F8A85 does not exist in the job cache: attempting to re-acquire it from the server...

12/20/2010 09:32:07,,Error,[000] Failed to retrieve job 0xB26B51B567B16C45940C9AA7132F8A85 from the server


12/20/2010 09:32:07,,Warning,[000] Job 0x630FB2CAF3AB084DA67CDEAF89F91E92 does not exist in the job cache

12/20/2010 09:32:01,,Error,[000] Refresh of schedule 98105 failed because the parent job (0x630FB2CAF3AB084DA67CDEAF89F91E92) was not found in the job cache

12/20/2010 09:32:01,,Error,[000] Failed to retrieve job 0x630FB2CAF3AB084DA67CDEAF89F91E92 from the server

12/20/2010 09:32:01,,Error,[298] SQLServer Error: 3621<c/> The statement has been terminated. [SQLSTATE 01000]

12/20/2010 09:32:01,,Error,[298] SQLServer Error: 2601<c/> Cannot insert duplicate key row in object 'dbo.sysjobactivity' with unique index 'clust'. [SQLSTATE 23000]

12/20/2010 09:32:01,,Warning,[156] Job 0x630FB2CAF3AB084DA67CDEAF89F91E92 does not exist in the job cache: attempting to re-acquire it from the server...

12/20/2010 09:32:01,,Error,[000] Failed to retrieve job 0x630FB2CAF3AB084DA67CDEAF89F91E92 from the server


I’ve never seen them before, or they happen very rare, while currently they happen every 2 - 5 min. So far I cannot see that those errors have any impact, but their number and regularity is quite disturbing. Why it happens and what can be done about that?


Also, by now there are hundreds of thousands jobs accumulated in SSRS SQL Server Agent Jobs folder (and corresponding msdb system tables of course), and it seems that vast majority of them is just outdated garbage which is just sitting there. Is there any way to safely cleanup those system tables?

Thank you,





Our application requires SQL Server Express. To avoid a problem with pre-existing MSXML 6.0 ( see http://social.msdn.microsoft.com/forums/en-US/sqlsetupandupgrade/thread/6fb98276-8fd6-485f-8785-ffddb5038399/ for example) we have been recommending that the the users fetch the Cleanup Utility (MSICUU2.exe) to remove MSXML 6.0.

However the Cleanup utility is now no longer available. We could continue to distribute it ourselves with our installation, but this does not seem the correct thing to do.

What is the correct way to remove MSXML now?




Hi, reaching out for any guidance for a problem I am seeing currently, one of my SQL servers is not releasing space after rows are deleted.

I am running SQL Server 2008 Enterprise x64 with SP1 CU4 (10.0.2734) and have a four node peer-peer replication configuration.

I am seeing large numbers records ready to be consumed by the ghost cleanup task via sys.dm_db_index_physical_stats (ghost_record_count), however these counts do not decrease. 

Strangely I am only experiencing this issue on one of the servers in the four node peer-peer configuration, that is the other three nodes successfully cleanup deleted rows with their respective ghost_record_counts eventually being reduced to zero.  The node that is experiencing this issue was the principal/initial node used to restore/setup the other nodes in the peer-peer replication topology.

I have tried both reorganizing and rebuilding the effected indexes, however this does not change the ghost_record_count figures after completion.  A full CHECKDB also does not yield any error/consistency issues. 

Help? :)



I have set a LDAP filter to only pull in active user profiles.

This has resulted in the following:

Total number of user profiles: 12,336
Number of active user profiles:6,370

How do I get the timer service to automatically remove the ~6000 inactive profiles?

The 'MySite Cleanup job' is running hourly,

Farm details: SharePoint Server 2007 SP1 with August 2008 CU.





Good Day,

I am having issue with a Service Application I created so I tried to delete it thru central admin, but it didn't delete it just says it is 'stopping'.  And it has been stopping for several days.  So I decided to run the powershell command "Remove-SPServiceApplication ab609cca-f141-42a7-8810-9582db74a898 -removedata" (I selected A for Yes to all) and it sat there and sat there and after leaving it for the weekend it eventually returned:

Remove-SPServiceApplication : The timer job did not complete running within the allotted time.

At line:1 char:28

+ remove-spsperviceapplication <<<<< ab609cca-f141-42a7-8810-9582db74a898 -removedata

     + CategoryInfo : InvalidDate: <MicrosoftShares...viceApplication:SPCmdletRemoveServiceApplication> [Remove-SPServiceApplication], TimoutExeception

     + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletRemoveServiceApplication


I was running the powershell cmd as admin when it asked if i wanted to perform the action it returned the name of the service app, so i know the GUID was correct (i got the guid from central admin) the service app is the user profiles service app



It's a very weird problem: SQL 2005 keeps making backups of the transaction logs every hour, even after removing all maintenance plans and jobs.

The msdb maintenance plan en job tables are all empty, logshipping is not configured and the logshipping related msdb tables are empty. It could be an old entry left behind by mirroring, but I don't know in which tables to look for that.


Dear All,

I have scheduled job for querying output & asve it into particuler folder....

but in the top of file i getting the message like

"Job 'bustd_Daily_Query_Output_13July09' : Step 1, 'Query1' : Began Executing 2009-07-13 16:32:06"

I want to remove this & want output in txt file format without above header....

Ravendra C


I recently did an upgrade of an application with several databases. After the upgrade I noticed that one of the old databases, wich is part of the maintenance plan are no more, it's deleted and after that the mainenance plan fails, of course. But my question is, can I remove the deleted database from the maintenance plan or do I have to do as I've used to do, create a new maintenance plan ? The deleted database are not shown in the mainenance plan wizard

MS SQL 2005 sp3


\\Jonas B


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure