I have simple SQL application which uses MS-SQL localdb file(.mdf). And I want to copy this localdb file(.mdf) to another folder whenever the application is closing as backup purpose.
However, below simple code brought IOException as titled of this question. My application always stays unconnected with localdb file(.mdf) if there's no user's specific button click.
I've found other cases but my poor knowledge is not enough to understand even what is similar.
I always highly appreciate your excellence. Thank you so much !
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);
}
}