Damage to the record due to power loss

Sep 26, 2016 at 2:02 PM
Hello all. We got an issue with the damaged rows, appearing after sudden power switch off. We have the devices, that sometimes suddenly shutting down by the users. After devices load back we often face with the keys in the database with no records behind it. Any attempts to get data, using selection methods, raise "System.OverflowException", because database engine is trying to read data from nonexistent part of the file. Each time when we get the broken records, we see (by the logs) that the device was shut down during the data insertion or commit. Is there any solution to save data from damage in case of sudden power loss?
DBreeze version: 1.74.2016.329.
Sep 26, 2016 at 2:23 PM
Please, describe devices, OS, runtime.
Sep 26, 2016 at 2:48 PM
It's a fundamental property, that overwrite of the physical data on the disc happens only after backup data is recorded.
All filestreams are created with FileOptions.WriteThrough option and before any overwrite Flush is called.
We don't have data losses in our environment with HDDs and SSDs also with Android/iOS devices with integrated NAND-flash.

May be problem is MONO or used SD-Cards. Please, describe your environment.
Sep 27, 2016 at 7:02 AM
Environment description.
OS: Windows XP, version - 5.1.2600.196608, SP 3
Runtime: .NET v3.5
Memory: 1-2 GB (depend on the device)
File system: NTFS
Sep 27, 2016 at 7:55 AM
Edited Sep 27, 2016 at 7:57 AM
There can be 2 problems. One of it the ancient HDD, who doesn't give a guarantee for a small chunk write (modern give guarantee for 512 bytes chunk).
Try to install newest generation HDD.
Second try to get exactly this compilation DBreeze_1_078_2016_0921_NET35_Win. (the same for 1.74 is also OK Release history)

About OS.
For .NET35 we use special Flush, because of bugs in FileStream.Flush(true).
 [System.Runtime.InteropServices.DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
        private static extern bool FlushFileBuffers(IntPtr hFile);

        public static void NET_Flush(FileStream mfs)
            IntPtr handle = mfs.SafeFileHandle.DangerousGetHandle();

            if (!FlushFileBuffers(handle))
                throw new System.ComponentModel.Win32Exception();
It definitely works on Win7 and higher. XP may have more deeper problems.
I know, it can be hard to upgrade OS, but it may be a problem.
Sep 27, 2016 at 1:09 PM
Ok, thanks. Will try the compilation, that you mentioned. It could be a solution. Unfortunately, updating of HDD or OS is not acceptable for us by now.
Oct 4, 2016 at 1:51 PM
Thanks a lot for your help. We used mentioned compilation (DBreeze_1_078_2016_0921_NET35_Win) and all devices is working fine so far.
Oct 4, 2016 at 2:03 PM
Very well and good luck!