简体   繁体   English

备份和还原SQLCE .sdf数据库

[英]Backup and Restore a SQLCE .sdf database

My application needs to backup and restore .sdf files. 我的应用程序需要备份和还原.sdf文件。 There is a single dataSet the the whole application and some bindngSource and table adapters on forms using this same dataset. 使用相同的数据集,整个应用程序只有一个dataSet以及表单上的某些bindngSource和表适配器。

Just for a sake of test I tryied to copy the .sdf in runtime for a backup folder and back to restore it and I got my application not finding the file like it was not there anymore. 为了测试起见,我尝试在运行时将.sdf复制到备份文件夹中,然后再还原以恢复它,但我的应用程序找不到该文件了,就像不再存在该文件一样。

How should I manage connections to open and close the database since the dataSet do it automaticaly at begin and end of my application? 由于dataSet是在应用程序的开始和结束时自动执行的,因此我应该如何管理打开和关闭数据库的连接?

Got the answer 得到了答案

http://social.msdn.microsoft.com/forums/en-US/sqlce/thread/79d2f8a2-1366-4d14-8c61-220f47183368/ http://social.msdn.microsoft.com/forums/zh-CN/sqlce/thread/79d2f8a2-1366-4d14-8c61-220f47183368/

(...) (...)

assign the OpenFileDialog.RestoreDirectory flag to true and then after it closes the original directory will be restored prior to the open dialog....that way you don't need the Directory.SetCurrentDirectory. 将OpenFileDialog.RestoreDirectory标志分配为true,然后在它关闭后将在打开对话框之前还原原始目录。...那样您就不需要Directory.SetCurrentDirectory。

fileChooser = new OpenFileDialog();
fileChooser.RestoreDirectory = true;

(...) (...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM