Today’s post covers a specific error you may receive when trying to delete an Audit Log. Note that while Dynamics 365 users in both on-premises and online environments can manage the Audit Log, for purposes of demonstration today, we’ll focus on managing the process in an on-premises environment only.

1. Start by clicking Settings > Auditing > Audit Log Management, as shown below:

audit log

audit log

2. Select the Audit Log you wish to delete and click Delete Logs.

audit log

3. If you didn’t hit an error, congratulations! Today’s blogpost wasn’t meant for you. But if you did get an error like the one below, please keep reading!

audit log

4. In the error message box, click Download Log File. You will receive the following message: “There are no partitions ending before the given date.” In context, it will look like this (note the highlighted portion):

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #B015AC8CDetail:

<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts“>

  <ErrorCode>-2147220970</ErrorCode>

  <ErrorDetails xmlns:d2p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic” />

  <Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #B015AC8C</Message>

  <Timestamp>2018-11-19T14:59:57.82726Z</Timestamp>

  <InnerFault>

    <ErrorCode>-2147220989</ErrorCode>

    <ErrorDetails xmlns:d3p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic” />

    <Message>There are no partitions ending before the given date</Message>

    <Timestamp>2018-11-19T14:59:57.82726Z</Timestamp>

    <InnerFault i:nil=”true” />

    <TraceText i:nil=”true” />

  </InnerFault>

  <TraceText i:nil=”true” />

</OrganizationServiceFault>

This error is likely the result of direct deletes/changes being made to the audit table, as this is not a supported method of audit log management. Because the audit base table is partitioned, making direct SQL updates can lead to this type of issue. With that in mind, the next step in the process is recreate the audit base table. WARNING: since this is an unsupported change, it is advised that you take a full database backup before recreating the table!

5. To recreate the audit base table, log in with a user that has full read/write access to the CRM audit table. Expand the Indexes and right-click on the PrimaryKey_Audit index, as shown below. From the popup menu, select Script Index as > DROP And Create To > New Query Editor Window.

audit log

6. Run the query to recreate this index. Once this has been completed, you will be able to delete the log partition within Dynamics.

Now you know what to do when you hit that stubborn “Unexpected Error.”

Need more Dynamics 365 tips and tricks? Be sure to subscribe to our blog for the latest!

Happy Dynamics 365’ing!

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.