1

I am trying to make a backup module for my application, here is my code:

try
{
    string newDbName = Application.StartupPath + @"\Database1.accdb";
    MessageBox.Show("The current directory is: " + newDbName);
    File.Copy(backupPicker.FileName, newDbName, true);
    MessageBox.Show("Restaurare efectuata cu succes.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
} catch (Exception ex)
{
    MessageBox.Show("Nu s-a putut restaura reerva.\nMai multe informatii despre aceasta eroare pot fi gasite in jurnalul de erori.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

But my application doesn't even run! Here the error message that I get from the debugger:

enter image description here

But actually, my application has access allowed to that location. What can I do?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Victor
  • 13,914
  • 19
  • 78
  • 147

2 Answers2

2

I believe you are using "Database1.accdb" as resource in your application but it is read only because of TFS. Close VS, delete the file, or make it read-only false, rebuild the project. It happens soooo many times to everyone.

Here have a look

Community
  • 1
  • 1
No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
2

Probably this is what could have happened, I suspect Your application is still running behind not yet terminated. so it will be accessing the files in StarupPath. Or you would have opened Database1.accdb in some other program.

To fix this Just Delete all the binaries from bin and obj folders then restart VS. If that doesn't help then open TaskManager Kill all suspected processes related to that file.

Hope this helps

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189