Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Cleaning up orphaned attachments

Posted on by Microsoft Employee

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

  • kunihih Profile Picture
    kunihih on at
    RE: Cleaning up orphaned attachments

    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;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cleaning up orphaned attachments

    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
    kunihih on at
    RE: Cleaning up orphaned attachments

    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
    Community Member Microsoft Employee on at
    RE: Cleaning up orphaned attachments

    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

  • Suggested answer
    kunihih Profile Picture
    kunihih on at
    RE: Cleaning up orphaned attachments

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans