Visual studio项目中的Sql server CE 4.0突然丢失数据
我不确定这是我这边的设置问题还是一些错误,但我面临着一个非常奇怪的问题。
我正在 VS 2010 Winforms 项目中针对 SQL Server CE 4.0 进行开发。它像这样保存在项目中
现在发生的事情是,由于某种奇怪的原因,每当我遇到我的应用程序出现异常或对数据库进行架构更新,我丢失了所有测试数据。不仅仅是一张表,而是所有表,整个数据库(除了模式对象)。
请记住,我没有做任何事情来从模型或任何东西重新生成数据库。它只是删除所有数据,目前甚至无法完全重现。完全不可预测。即使数据被删除后,架构仍保持不变。
有人可以帮忙吗?
I am not sure if this is a setup issue from my side or some bug, but I am facing a really wierd problem.
I am developing against SQL Server CE 4.0 in a VS 2010 Winforms Project. It is kept in the project like so
Now what happens is, for some strange reason, whenever I encounter an exception in my application or do a schema update for database, I lose all my test data. Not just one table, all of it, entire database except for the schema objects.
Remember, I am not doing anything to regenerate the database from the model or anything. It just deletes all the data, and currently it is not even fully reproducible. Completely unpredictable. The schema remains intact even after the data is deleted.
Can any one help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我想出了解决方案 - 我很愚蠢,但我认为其他人也会犯同样的错误,所以这里是 -
我使用连接字符串作为 |DataDirectory|\LocalDB.sdf 并期望它从项目目录中获取它 -事实证明它是从调试文件夹中获取的。现在我知道了,这是有道理的。
因此,每当我进行架构更新时,原始数据库都会发生更改,因此它会替换调试文件夹中存在的 LocalDB。由于项目中的数据库从未有任何数据,因此我过去常常不必要地获取空数据库。
Okay I figured out the solution - very stupid of me, but I think others can make this same mistake so here goes -
I am using the connection string as |DataDirectory|\LocalDB.sdf and expected it to take it from the project directory - turns out it takes it from the debug folder instead. Makes sense now that I know it.
So whenever I do a schema update, the original database gets changed so it replaced the LocalDB present in the debug folder. Since the db in the project never had any data, I used to get the empty database unnecessarily.
实际上,在 SQL Server CE 数据库(例如架构中)发生更改后,它会用新副本替换应用程序内的数据库。如果sqlserver ce中的数据库与应用程序内的数据库具有不同的数据集,则应用程序内以前的数据将丢失。
Actually, after a change in the SQL Server CE database (in the schema, for example), it replaces the database inside the application with a new copy. If the database in sqlserver ce has a different set of data than the database inside the application, the previous data inside the application will be lost.