How can I corrupt a SQL CE database?

I want to be able to check for a damaged database at startup and then repair it programmatically. I can do it easy enough.

My problem is that I want to verify that everything works as I expect. Does anyone know a way to targetedly corrupt a database so that I can test my code?

+4
source share
1 answer

You can load the SDF file into a byte array, arbitrarily change some bytes and save the array on top of the original file (or, for that matter, load the file into a hex editor and put all of Shakespeare's monkeys on it).

I think this will do what you want without doing what you want. In my experience, the problems that I had with corrupted SqlCE databases were not fixed with SqlCeEngine.Repair (see this answer to the corresponding question). It is possible that Repair can fix a database in which some of its bytes are randomly changed, but I’m sure it will depend on where the change occurred in the file (for example, on the data page somewhere or in the file header, if there is).

+2
source

Source: https://habr.com/ru/post/1308286/


All Articles