如何损坏 SQL CE 数据库?
我希望能够在启动时检查损坏的数据库,然后以编程方式修复它。我可以轻松做到这一点。
我的问题是我想测试事情是否按我预期的方式工作。有谁知道有一种方法可以故意破坏数据库以便我可以测试我的代码?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 SDF 文件加载到字节数组中,随机更改一些字节,然后将数组保存回原始文件(或者就此而言,将文件加载到十六进制编辑器中,然后使用所有莎士比亚的猴子)。
我认为这会做你想做的事而不做你想做的事。根据我的经验,SqlCE 数据库损坏所遇到的问题并没有被
SqlCeEngine.Repair
修复(请参阅 此答案相关问题)。Repair
可能可以修复部分字节被随机更改的数据库,但我确信这取决于文件中发生更改的位置(例如在某个数据页中或在文件头中(如果有的话)。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 thatRepair
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).