Wednesday, April 8, 2015

AX 2012 R3 - Data Import Export Framework - Key not valid for use in specified state

I came accross this issue after replacing the Business Database in a Test Environment. This should not be a very common issue, but I'm sharing it since the possible solution is rather simple.

Scenario

When validating a Data Source (DB) from the form Data Import Export Framework > Setup > Source Data Formats, the following exception was thrown:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.

After examining the underlying code, it pointed to the a specific table.

Solution/workaround

NB! I have deliberately choosen not to reveal the real table or column name (pretty obvious)

  1. Run a simple SELECT from the table.
  2. Check if a value is stored in the "Secret" Column for the Data Source Type (typically DB:Database).
  3. If you find a value in this "Secret" Column, try to run a simple UPDATE statement to clear the value.
  4. Do a Log Off - Log On Sequence in the AX Windows Client and try to validate the Data Source again and you will probably have solved your issue.
Hypothesis

When replacing the Business Database, it's always a Best Practice to create a new GLOBALGUID. It could be that the GLOBALGUID is used as the or part of the Encryption Key. After changing the GLOBALGUID, it's no longer possible to Decrypt the information stored in the table (and that's the way it should be).

4 comments:

  1. Can you please provide more details on which table this needs to be fixed?

    ReplyDelete
  2. For those of you asking for details, do the following:
    -Navigate to Data Import Export > Setup > Source Data Formats
    -Right-Click in the Right part of the Source Data Formats Form and Choose Personalize
    -Look in the Tab called Query and you will find what you need

    ReplyDelete
  3. The work around you suggested to clear the data from "Secret" column would remove the encrypted data and we could not be able retain the data in "Secret" column.Am i understanding your work around correctly ? or you trying to explain something else ?

    Thanks,
    Manish Verma

    ReplyDelete
  4. Thank you for leaving a comment/question. Yes, it will, but it should not be critical in any way - this was about restoring the Business Database from one environment to another and the possible relationship to the GUID unique to each environment. As with many areas in AX, a lot of details are not well documented. OK?

    ReplyDelete

Feel free to post your comments! Comments will be moderated