Fix Error Microsoft Exchange Server Storage.Common.DuplicateKeyException

Summary: You may encounter the error DuplicateKeyException when migrating from Exchange Server 2010 to 2016. In this post, we’ll be discussing the ways to fix this error. In case the error occurs due to database corruption, you can use Exchange native tool – ESEUtil or a third-party Exchange recovery tool to repair and recover the database.

Although your Microsoft Exchange Server is working fine, you would still need to upgrade to a newer version. With upgrade, you get new features and updates. These include security and protection, better performance, and various new features, like mobility and collaboration. And above all, the peace of mind as you get support from Microsoft. This would involve several things such as the purchase of licenses, possible migration, and upgradation of the Active Directory server to a supported Operating System, and upgradation of the Outlook application installed on the client machines.

When upgrading your Exchange Server to a newer version, you also need to confirm that you can upgrade from your current version to the version you intend to install. For example, you cannot migrate from Exchange Server 2010 to Exchange Server 2019 directly. For this, you need to first install and migrate to Exchange Server 2013 or 2016, decommission the Exchange Server 2010, and then migrate to Exchange Server 2019. So, the version and co-existence matrix need to be consulted before purchasing or planning your migration. Sometimes, issues occur during the upgrade from an Exchange Server 2010 to an Exchange Server 2016.

After the migration is complete from Exchange Server 2010 to Exchange Server 2016, you might encounter several events in your Event Viewer with the ID 1002. This alone doesn?t mean much but if you open the event, you will get a message similar to the one below.

Unhandled exception (Microsoft.Exchange.Server.Storage.Common.DuplicateKeyException: JetTableOperator.Insert ---> Microsoft.Isam.Esent.Interop.EsentKeyDuplicateException: Illegal duplicate key at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) at Microsoft.Isam.Esent.Interop.Server2003.Server2003Api.JetUpdate2(JET_SESID sesid, JET_TABLEID tableid, Byte[] bookmark, Int32 bookmarkSize, Int32& actualBookmarkSize, UpdateGrbit grbit) at Microsoft.Exchange.Server.Storage.PhysicalAccessJet.JetTableOperator.Insert(IList`1 columns, IList`1 values, Column identityColumnToFetch, Boolean unversioned, Boolean ignoreDuplicateKey, Object& identityValue)

--- End of inner exception stack trace ---

How to Resolve the Error: Microsoft Exchange.Server.Storage.Common.DuplicateKeyException?

  1. This issue can have multiple forms. You first need to ensure that the server?s resources are working fine. Ensure that the memory and CPU are idle and in normal usage. You need to also make sure that you have ample space in your server. Once this is confirmed, make sure that all services of the Exchange Server are running. Check that the Exchange Server 2016 was not installed with an old build and make sure that Exchange server is fully patched to the latest Cumulative Patches. If in doubt, check with your supplier or Microsoft support.
  2. Next, check the Event Viewer as it?s your first source of information to try to identify the cause of this event. Check the System Event log for any disk related issues as performance or a soon to be damaged hard drive in your disk array can cause such problems.
  3. If this is not the case, take a backup of the current database or the database which is giving this problem to a safe location. So, if the database is damaged in the recovery process, you can restore it from there.
  4. Now, create a new mailbox database in your Exchange Server and move all the mailboxes and resources to this new database. If something is wrong with the current mailbox database, this will be cleared as the mailboxes are transferred to a fresh database. After all the resources are migrated to a new database, you can safely delete the old database. This should clear the issue and the Event ID 1002 should not appear anymore.

What to do if Database is Corrupt?

In some cases, this error indicates corruption in your database. If this is the case and the database would not mount, you would need to consider the recovery process by using Exchange Server native tools, like ESEUtil.

ESEUtil can be executed with two methods ? Soft Recovery and Hard Recovery. Soft recovery might fix some minor corruptions and hopefully the database would mount afterwards. Here?s the command to perform Soft Recovery:

Eseutil /r e00 /l "<location of logs>" /d "<location of database>"

The hard recovery process is a bit risky and must only be used as a last resort. Why is this? Well, the first thing is that the process would literally purge anything which is deemed as corrupted. This would also include data which is falsely tagged as corrupted. This means that you will have data loss and you cannot quantify how much data will be deleted from the database. Below is the command to perform hard recovery:

EseUtil /p <database filename>

You would also need to factor in the support perspective from Microsoft. Running a hard recovery on a mailbox database will hard code mark the database. This will breach the support contract from Microsoft.

Conclusion

You can try to recover the database using the ESEUtil. However, there is no guarantee that it will be successful. It will take time and resources to resolve this issue, along with huge administrative effort. To avoid hassle and reduce administrative effort, you can use a Exchange server recovery tool, such as Stellar Repair for Exchange. With this application, you can easily open and browse corrupt Exchange (EDB) databases, from any version of Exchange Server. You don?t need an Exchange Server to open an EDB file. You can export granularly to PST or other file formats. You can also use the application as a migration tool. You can export directly to a live Exchange Server of any version or Office 365 tenant.

Related Post