SQL Server CE +外接程序读写冲突避免?

问题描述:

我们有一个Office插件,它使用Sql CE和通常的DBConnection到文件系统中的* .sdf('C:/... etc ...').当我们启动具有Sql CE增强的Office插件的应用程序的两个副本(测试用户可能错误地做的事情)时,Sql CE数据库已损坏,Office插件无法再访问其数据.

We have an Office Addin that uses Sql CE with the usual DBConnection to a *.sdf in the filesystem ('C:/...etc...'). When we start two copies of the application having the Sql CE-augmented Office Addin (testing what a user might do by mistake) the Sql CE database becomes corrupted and the Office Addin can no longer access its data.

似乎我们缺少一些避免看似明显问题的基本方法.到目前为止,每个人都知道Sql CE不会锁定其行,从而导致多次写入同一* .sdf可能导致的损坏.

It seems like we are missing some basic way of avoiding a seemingly obvious problem. By now everyone knows that Sql CE does not lock its rows allowing the sort of corruption that multiple writes to the same *.sdf can cause.

也许答案是不要那样做;"并且该Sql CE并非旨在处理这种情况.但是,可以肯定的是,大多数Sql CE应用程序都有错误地启动多个进程并尝试写入同一* .sdf的类似风险?

Perhaps the answer is "don't do that;" and that Sql CE is not designed to handle this case. But surely most applications of Sql CE have a similar risk of mistakenly starting more than one process and attempting to write to the same *.sdf?

我们喜欢Sql CE的小巧,*和易于集成到插件的功能.但是我们已经看过Sql Server Express和2008的比较: http://下载. microsoft.com/download/A/4/7/A47B7B0E-976D-4F49-B15D-F02ADE638EBE/Compact_Express_Comparison.doc

We like Sql CE's small size, free-ness, and easy integration to our addins. But we have looked at Sql Server Express and 2008 comparisons: http://download.microsoft.com/download/A/4/7/A47B7B0E-976D-4F49-B15D-F02ADE638EBE/Compact_Express_Comparison.doc

如果我正确理解您的用例并不需要两个正在运行的应用程序,则只要用户错误地捕获了此错误即可.

If i understand that correctly your use-case does not really require two running applications, you just need to catch the error if the user does so by mistake.

在这种情况下,检查您的插件是否已在运行(无论您的语言/框架对此是否支持...)就足够了.如果还有另一个实例,请不要实例化该插件.

In that case it should be sufficient to check if your addin is already running (whatever your language/framework supports for that...). If there is another instance, just don't instantiate the addin.