This is not a query. Its a summary of our solution to get around the problem of corruption in SQL Compact Database files with (almost) definite success. SQLCE Corruption is
If using SQL Server CE 4.0 there is a known issue that may prevent data from being flushed to disk (AT ALL). https://support.microsoft.com/en-us/kb/2979868 and hotfix https://support.microsoft.com/en-us/kb/2960153
In their own words:
Assume that you have specified the flush interval in the maximum number of seconds in the connection string before committed transactions are flushed to disk in Microsoft SQL Server Compact 4.0. In this situation, the committed transactions may take much longer time than the flush interval to be flushed to disk or may not even be flushed to disk. Additionally, data loss occurs if there is an abnormal program termination.
The hotfix that resolves this problem is included in an on-demand hotfix update package for SQL Server Compact 4.0 Service Pack 1.
The workaround supplied is to use transaction.Commit(CommitMode.Immediate)
around the block you want to make sure gets flushed