Unable to compile Sql CE script file during SCCM client install or upgrade

I've had issues with the SCCM client on our internet (IBCM) server. At first it was the issue with configuration manager software not on C-drive, and client patches failing to apply. Then with SCCM 1511 and 1602 client installs on the server resultet in

MSI: Setup was unable to compile Sql CE script file F:\SMS_CCM\StateMessageStore.sqlce.
The error code is 80004005.    ccmsetup.

This is due to the old Sql CE databases still being present. 

To fix this, uninstall all SCCM client components. Find the Windows Installer Code with this Powershell command.

(Get-WmiObject -Class CCM_InstalledProduct -Namespace "root\ccm").ProductCode

Then move the following files to a backup folder. These are the old client Sql CE database files. They are located in the client install folder %windir%\CCM\ or in the SMS_CCM folder).

  • CcmStore.sdf
  • CertEnrollmentStore.sdf
  • ComplRelayStore.sdf
  • InventoryStore.sdf
  • UserAffinityStore.sdf

Abort any running ccmsetup processes by stopping any ccmsetup services running, and then run the following command from you SCCM client install folder (or %windir%\ccmsetup):

ccmsetup.exe /uninstall

Then install the client as usual with ccmsetup.exe