【发布时间】:2016-03-07 10:43:29
【问题描述】:
我有一个使用 MS-SQL localdb 文件 (.mdf) 的简单 SQL 应用程序。 每当应用程序作为备份目的关闭时,我想将此 localdb 文件(.mdf)复制到另一个文件夹。
但是,下面的简单代码带来了标题为这个问题的 IOException。 如果没有用户的特定按钮单击,我的应用程序始终与 localdb 文件(.mdf)保持断开连接。
我发现了其他案例,但我的知识不足以理解甚至类似的情况。
我一直非常感谢您的卓越表现。非常感谢!
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("really want to exit?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
e.Cancel = true;
}
else
{
var greendbfileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), string.Format("greendb_{0}.mdf", personID));
var copied_greendbfileName = string.Format(@"C:\greendb_{0}.mdf", personID);
File.Copy(greendbfileName, copied_greendbfileName);
Environment.Exit(0);
}
}
【问题讨论】:
标签: c# sql copy ioexception localdb