I was in the process of moving Dynamics GP and Management Reporter for a client and came across an issue deleting a company in the Configuration Console for MR.
It seems that my client had old companies listed which they could not get rid of. When trying to delete the company in the Configuration Console, the following error would come up:
This company is referenced by an existing report definition or reporting tree definition. Remove these associations before deleting the company.
My client had already checked through all of their Report Definitions and Tree Definitions and the old companies were not referenced.
I decided to have a look at the database and see if there were entries linking the company somehow.
My first port of call was to find the Company IDs of the companies in question. To do this, I ran the following in SQL Management Studio against the ManagementReporter database:
SELECT * FROM ControlCompany
I got the Company IDs from the ID column and then ran the following:
SELECT * FROM ControlReport WHERE COMPANYID = 'XXX'
SELECT * FROM ControlTreeDetail WHERE COMPANYID = 'XXX'
The COMPANYID is the ID that you picked up from the ControlCompany table. This showed a multitude of results, which confirmed my thoughts that there are linked in the database, even though none can be found in the Report Designer UI.
I now knew that it was necessary to remove data from the database.
ALWAYS BACK UP YOUR DATABASE BEFORE DELETING OR AMENDING RECORDS AS A PRECAUTIONARY MEASURE.
From here, I deleted the records relating to the old companies in SQL:
DELETE FROM ControlReport WHERE COMPANYID = 'XXX'
DELETE FROM ControlTreeDetail WHERE COMPANYID = 'XXX'
Once these records were gone, I was able to delete the old companies through the Configuration Console.