Detach local database .mdf, copy, attach the new file
问题 I tried to detach my local database .mdf copy it in another folder and attach the new file at launch and copy to the older folder when closing. It seems to works at launch but i have an error when the form closing : The process cannot access the file 'C:\ProgramData\MyData\db1.mdf' because it is being used by another process. That's my code : public Form() { InitializeComponent(); DetachDatabase(); CopyDb(); AttachDatabase(); AppDomain.CurrentDomain.SetData("DataDirectory", Data.MyNewFolder);