LABEL corruption in Model Database

3. September 2015

Problem statement

If you encounter problems with labels in Dynamics AX 2012, please read forward, this might give you an inside of what the problem is. See if you can answer yes to any of the below questions

  • I am using TFS to build my application
  • I have cleaned up my ModelStore using AXUTIL delete /model:??
  • I have imported wrong label, moved it to a temp model and deleted that model

I have found a problem in the AXUTIL tool, this has been reported to MS, so let me guide you through this

My Application is a AX2012 R2 CU7 6.2.2000.171

Root Cause

In the MODEL Database a labels has various references, in this example my LABEL files is ‘ITM’

  • All Labels is references in Element type 117 as the actual LABEL AOT Element

Select * from ModelElement where ElementType = 117 and Name = ‘ITM’

  • The actual element is in placed in ModelElementdata
    • Select * from ModelElementdata where ElementHandle = (Select ElementHandle from ModelElement where ElementType = 117 and Name = ‘ITM’)
  • All the label language you can find like (EN_US)
    • Select * from ModelElement where ElementType = 118 and name = ‘EN_US’ and RootHandle =(Select ElementHandle from ModelElement where ElementType = 117 and Name = ‘ITM’)
  • With this reference you can now find the actual Label Data using
    • select * from ModelElementLabel where ElementHandle = (Select ElementHandle from ModelElement where ElementType = 118 and name = ‘EN_US’ and RootHandle = (Select ElementHandle from ModelElement where ElementType = 117 and Name = ‘ITM’))

The problem however is the following

When you delete a model in AX using the AXUTIL tool it does NOT delete the ModelELementLabel.

The problem now grows exponentially when you reimport the same label again, because the Element Handle of the label you import potentially is not the same and you will end up with orphan’s records. This would not be a problem, if AOS always would look at the Element handle, other than you will have a lot of dirty records.

But the problem is that when AOS stop and flush it’s CACHE, the Label files is supposed to be flush back in the model store, this does not happen because the AOS server from a perspective LABELS and LABEL ID think the data is there but from a perspective of DB integrity Foreign Key constraint the data is not there.

So when the AOS server restarts it will simply purge (Actually it creates a BAK fil og the LABEL.ALD file) and then recreated an empty ALD file So from my chair it looking like the process of creating label files is using the Element Handle as reference, but the process of clearing Cache and pushing labels back to the model store it uses the LABEL ID, in my case ITM


So the solution is actually surprisingly simple

Just get the old LABEL data out of the Modelstore

In my case

DELETE from ModelElementLabel where module = ‘ITM’

Things to watch

Need not to remind you that you are working on modelstore, so this operation has to take place and be tested in a development environment

Also you should always have your AOS turned off, when doing stuff like this

And you should always have a backup of you MODEL DB, to revert back and retry the solution more than ones

Please check you ModelElementLabel table for old entries of LABELS that is not used anymore, you might be suprised what you find

So where can this happen.

In my case we have cleaned up a model store and I was resetting the BUILD application. My approach on the BUILD is to have a clean DB backup of the Model store and Business data that I restore from as the baseline.

Now because I restored a production DB and cleaned it up, I did not realize that these LABEL elements was sitting there. So when I ran the BUILD on top of this, including the IMPORT of labels I encountered this problem because my BUILD machine did not create the exact same Element Handle for the label file, as expected.

Potentially I can also see this happen if you by mistake import a label file in the wrong layer/model. You then create a temporary Model, move the label file over here, and delete the model

This is actually the only way to get a LABEL cleaned out of the system (And yet again not really)

Then you open AX in the correct layer and reimport the LABEL. If you are unlucky the label file will get another Element Handle and you can see this problem

 Hope this will help you

Leave a Reply