
TableSynchSetup.Mode::Force and Upgrade Codeunits when reducing the size of text or code fields
When designing Upgrade Codeunits, it is possible to specify in the upgrade function a brutal Force action performed at runtime as per documentation
https://docs.microsoft.com/en-us/dynamics-nav/upgrade-codeunits#upgradedunctions
|
Force |
The Microsoft Dynamics NAV Server will force the changes on the table and delete any data in fields that are affected by the change. This option is intended to be used for the tables and fields that you want to discontinue. If you want to save the data from this table, you should use the Copy or Move mode. |
With the advent of SaaS deployments and in Dynamics 365 Business Central Spring 2019 release (version 14.x), the execution of this parameter has been made more restrictive and until September 2020 Cumulative Update (CU) it would have thrown an error if the synchronization command would have run not under -ForceSync conditions.
NOTE: this restriction applies when changing the size of a column.
To showcase and reproduce the behavior, you could follow these repro steps:
OBJECT Codeunit 50333 UpgradeWithForce
{
OBJECT-PROPERTIES
{
Date=;
Time=;
Modified=Yes;
Version List=;
}
PROPERTIES
{
Subtype=Upgrade;
OnRun=BEGIN
UpgradeCustomer(TableSyncSetup);
END;
}
CODE
{
VAR
TableSyncSetup@1000 : Record 2000000135;
[TableSyncSetup]
PROCEDURE UpgradeCustomer@2(VAR TableSynchSetup@1002 : Record 2000000135);
VAR
DataUpgradeMgt@1001 : Codeunit 9900;
BEGIN
DataUpgradeMgt.SetTableSyncSetup(DATABASE::Customer,0,TableSynchSetup.Mode::Force);
END;
BEGIN
END.
}
}
Sync-navtenant : The following SQL error was unexpected:
String or binary data would be truncated.
The statement has been terminated.
At line:1 char:1
+ Sync-navtenant nav -Mode Sync
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (0:Int32) [Sync-NAVTenant], NavCommandException
+ FullyQualifiedErrorId : MicrosoftDynamicsNavServer$nav,Microsoft.Dynamics.Nav.Management.Cmdlets.SyncNavTenant
NOTE: If you try to use web or windows client now (or whatever client), you will see that the system is not accessible and you cannot connect.
NOTE: running Sync-navtenant BC140 -Mode ForceSync will perform the action.
The problem of ForceSync is related to an unwanted raise of permissions in synchronizing the environment that might introduce a problem if some other disruptive breaking change has been applied not on purpose.
To be sure that these unwanted changes does not break through, since September 2020 CU 14.17, it is made possible to specify the following server side parameter in customsettings.config file:
<add key="ForceSyncFromUpgradeCodeunit" value="true" />
After restarting the service, if a synchronization is performed with -Mode Sync and an upgrade codeunit has specified a Force option parameter, this will not throw any error.
All other unwanted breaking changes that does not pass through an upgrade codeunit with Force option parameter set will raise an error.
Below links to KB article and relevant TFS entry
|
364588 |
A SQL error displays in Sync-NAVTenant -Mode Sync when you synchronize with a TableSyncSetup Upgrade codeunit that runs with TableSynchSetup.Mode::Force. |
Please note that Dynamics NAV 2017 and backward versions, the synchronization with -Mode Force would have worked without the needs of specifying anything server side.
Dynamics NAV 2018 implemented the server side parameter already, since September 2019, with CU 21 https://support.microsoft.com/en-us/help/4518533/cumulative-update-21-for-microsoft-dynamics-nav-2018-build-35815
|
310480 |
An upgrade codeunit is specifying the Table Synch. Setup Mode that the force mode is not forcing the table synchronization as expected. |