views:

178

answers:

1

I want to be able to check for a corrupted database at startup, and then repair it programmatically. I can do that easily enough.

My problem is that I want to test that things work the way I expect. Does anyone know of a way to purposefully corrupt a database so I can test my code?

+1  A: 

You could load the SDF file into a byte array, randomly alter some of the bytes and save the array back over the original file (or for that matter, load the file into a hex editor and go all 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've had with corrupted SqlCE databases weren't fixed by SqlCeEngine.Repair (see this answer to a related question). It may be that Repair can fix a database that has had some of its bytes randomly altered, but I'm sure this would depend on where in the file the alteration occured (e.g. in a data page somewhere or in the file header, if there is one).

MusiGenesis