Unable to Delete a Business Unit CRM 2011

As you most likely know, CRM 2011 now allows you to delete Business Units.  A client recently reported an issue that occurred when they attempted to delete a business unit.  The error message displayed through the UI was:

“Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #E79AE80FDetail”

Since that didn’t provide me with enough information to effectively troubleshoot the issue I decided to run a trace on the server.  The trace file provided additional insight:

Crm Exception: Message: Generic SQL error., ErrorCode: -2147204784, InnerException: Microsoft.Crm.CrmException: Generic SQL error. —> Microsoft.Crm.CrmException: Generic SQL error. —> System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint “business_unit_queues”. The conflict occurred in database “CRMOrgDBName_MSCRM”, table “dbo.QueueBase”, column ‘BusinessUnitId’.
The statement has been terminated.

The above error indicates that the delete request could not be completed because there are dependencies that still exist on that Business Unit.  However, we could not see the dependent records when opening the Business Unit and selecting the links from the left navigation menu.  Instead, we had to take a different approach and the easiest way I found to resolve the issue was to take the following steps:

  • Run the following query against the businessunit table
    • Select businessunitid, name from businessunit where name = ‘name of business unit for deletion’
  • Copy the businessunitid and use it in the following query
    • Select name, description from QueueBase Where OwningBusinessUnit = ‘copied businessunitid’

After running the query we found several queues that were still referencing the Business Unit.  Therefore, we first needed to open the queue, remove all items from the queue and then delete the queue.  Below are the steps to complete that action:

  • Go to Workplace, Queues and find each of the queues in CRM and take the action to remove or delete all items from each queue
    • You can find the ‘Remove all Items’ action on the action menu
  • Go to Settings, Business Management, Queues, find each of the Queues and delete each one

Now that all dependencies to the Business Unit are removed, you should be able to successfully delete the Business Unit.

  • Go to Settings, System, Administration and delete the Business Unit

I hope this helps in the event you run into this issue.

Cheers

2 comments

  1. This is an old post but I just ran into the same problem, after running the queries above and then deleting the referenced queues the same SQL Server Error and trace message still appeared.

    What we then had to do in order to delete the Business Units was go and delete all the old ‘WIP-BIN’ queues that were hanging round as this organisation had been upgraded from CRM4 – http://msdn.microsoft.com/en-us/library/gg327885.aspx . These queues didn’t actually appear to be referenced in the queries in this article, but after deleting then we were able to delete the business units without error.

    Hopefully this little extra trick might help someone else!

  2. This is an old post but we just ran into the same problem, and after locating and deleting the referenced queues the same SQL Server Error and trace messages appeared.

    What we had to do next was delete out all the old ‘WIP-BIN’ queues (http://msdn.microsoft.com/en-us/library/gg327885.aspx) that were hanging around from the CRM4 -> CRM 2011 upgrade. After that we could delete business units without a problem.

    Hopefully this little extra step might help someone else!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s