web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Cleaning up orphaned attachments

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

CRM On Premise 8.2.X here. 

We noticed recently that our attachment table is getting rather large (120gb), on a closer inspection, in excess of half of this is attachments that have become orphaned due to the original email being deleted - but the attachments aren't deleted. 

I found some information online suggesting that back in CRM 2011 an extra task was added to the deletionservice to fix this, but i dont know whether thats still in place in 8.2.X, or where i'd go to investigate why it might be failing.

The SDK seems not to be an option, as it seems to pre-filter retrieve and delete requests to NON ORPHANED records. 

Example:

_service.Retrieve("activitymimeattachment", Guid.Parse("DE273EDA-F450-E911-80FE-005056893571"), new ColumnSet(true));

This will fail when fed any orphaned ID, but succeed when fed any attachment still linked to an email or email template.  

What can i do to workaround this, If there is indeed a cleanup task that might be failing - where do i go to find that so i can get it going, if not - what is the way to get rid of orphaned attachments? Am i missing a simple solution?

Thanks! Charles

I have the same question (0)
  • Suggested answer
    kunihih Profile Picture
    on at

    The deletionservice does delete orphaned attachments but this operation may be timing out because of the size of the table. The event log may be reporting this error but if not you may need to get a platform trace to confirm that it is a timeout.

    support.microsoft.com/.../how-to-enable-tracing-in-microsoft-dynamics-crm

    The deletion timeout can be changed by updating the value of the DeletionServiceDBCommandTimeoutInSeconds setting in the Deployment table in the MSCRM_CONFIG database. This setting has a default of 300 seconds(5 minutes). It may be worth temporarily increasing this value.

  • Community Member Profile Picture
    on at

    Hi


    Thanks for the feedback! I've had trouble finding much detail on the deletionservice. i'd like ot be able to troubleshoot it more accurately, how can i identify how/where it is scheduled, and what its doing?

    i daresay it is a timeout issue given we have 70 000 orphaned attachments!

    is it a system job, is it an SSIS task, etc? what might it be called?


    Can it be triggered manually?

    Charles

  • kunihih Profile Picture
    on at

    It is a asynchronous system job. The following page has more details on this job.

    docs.microsoft.com/.../crm-2013-maintenance-jobs

    There is also a tool that will allow you to change the schedules of these jobs. This can be used to run maintenance jobs on demand.

    1. Open the archive page archive.codeplex.com/

    2. Click 'Download Archive'

    3. Unzip the ZIP file

    4. Go to the folder, Releases > 3

    5. Add .zip extension to the end of the file in this folder (It's a GUID).

    6. Unzip the new zip file.

    7. Inside the unzipped folder is the CRM2016JobEditor.exe

    8. Copy this file to the {Letter}:\Program Files\Microsoft Dynamics CRM\tools\ directory.

    9. Run the .exe

  • Community Member Profile Picture
    on at

    Hello

    Thanks for this reply, using this i was able to locate the timing and event viewer entries.

    From what i can see however, there are no errors/timeouts, etc.

    If the Deletionservice isn't identifying these orphaned attachments, is there some way i can safely remove them, or is this a ticket to MS?

    Charles

  • kunihih Profile Picture
    on at

    I think you should collect the traces I mentioned in my first post while the deletion job is running and send the files with the MS ticket. It is possible to run the following deletion query to remove orphaned records but I don't recommend you do so until we can understand why the deletion is not being executed.

    Begin Tran;

    with DataToDelete as (select top (@numOfRecordsToBeDeleted) AttachmentId  from Attachment Att where  not exists

    (select AttachmentId from ActivityMimeAttachment Amt where Att.AttachmentId = Amt.AttachmentId))

    delete from DataToDelete option (maxdop {0})

    Commit Tran;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans