# Error when rebuilding the Reporting database: “Cannot initialize when there is work to do”

I have upgraded my Sitecore solution from 7.5 to 8.1 update 1. When trying to rebuild the Reporting database, I am getting the following error in the log files:

7084 2016:12:18 05:26:24 ERROR Exception when executing agent aggregation/rebuildAgent
Exception: System.InvalidOperationException
Message: Cannot initialize when there is work to do
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.IsFalse(Boolean condition, String message)
at Sitecore.Analytics.RangeScheduler.MongoDbRangeMap.Initialize(Guid left, Guid right, Int64 count)
at Sitecore.Analytics.Automation.Aggregation.Data.Processing.AutomationHistoryAggregatorManager.Start(List1 targetProvidersConfigPaths)
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at Sitecore.Analytics.Aggregation.History.ReportingStorageManager.ProcessRebuild()
at Sitecore.Analytics.Core.BackgroundService.Run()


Any ideas how to solve this?

This error means there is some unfinished work remaining from previous rebuilds or other data processing operations. There are two ways to fix this:

## Cautious approach

The cleanest way is to investigate your logs for errors that prevent the work from being completed. If you find anything, please create a separate question, since it'll be about a concrete data processing issue in your solution.

Once you fix the issues, the work will be finished and you'll be able to run a Reporting DB rebuild.

If you can't find any issues with data processing, or if don't care about any unfinished data processing work -

1. Back up the MongoDB database corresponding to the analytics connection string in your ConnectionStrings.config.
2. Drop the RangeMaps collection if it exists:

• If you have a standalone database instance, just call this command:

db.RangeMaps.drop()

• If the RangeMaps collection is sharded, you'll need to unshard it before dropping.

3. Drop all Range_* collections in the same way as you dropped RangeMaps.
4. Drop the AutomationRanges collection.
5. Drop the HistoryTasks collection.
• @MohammedSyam Also, drop Range_*` collections. I've updated my answer. – Dmytro Shevchenko Dec 19 '16 at 7:31