0

I have a database that is locking mdb's and such that I'd like to backup. However the tool (I have the source) I am using opens the file before backing it up and finds that it is locked.

Is there a way I can open it for read-only purposes?

For reference the tool uses C# and .NET 2.0 (but can be updated to 3.5).

Dhaust
  • 5,470
  • 9
  • 54
  • 80
Malfist
  • 31,179
  • 61
  • 182
  • 269

3 Answers3

5

The reason your tool locks the file is to prevent changes to the file as it is being backed up. For example, if you begun your backup, but halfway in the DBMS (i.e. SQL Server) decided to make a change to a file, then your backup would be corrupt.

I recommend you use the tools that are provided with your database solutions to perform a backup. The other option is to stop the database before backing it up.

Matthew Timbs
  • 435
  • 1
  • 4
  • 11
  • No, he has it backwards. The database has a exclusive read lock on the file, and the tool cannot get a lock. Matthew has it the other way around. – Samuel Mar 23 '09 at 21:40
  • 1
    Right, the DB has an exclusive lock on the data file BECAUSE the writers of the DBMS knew that to copy the file while the database is running is not a good idea, so they lock it. This is to prevent you from doing exactly what you're trying to do. – Matthew Timbs Mar 24 '09 at 17:48
  • What native backup tools would you use when using a Jet back end, as in this present question? You *did* read it before answering, right? – David-W-Fenton Mar 25 '09 at 03:48
  • Why yes, I did read your question. You didn't mention Jet in your original post. I'm not familiar with backup tools used for Jet databases, but the issue is the same no matter the DBMS. Try googling. – Matthew Timbs Apr 01 '09 at 14:29
3

If the DBMS is holding a write lock on the file, and you read it, you're risking the DBMS writing the file as you're reading it. Depending on what part was written, you could end up with a corrupt backup of the file. You're best off reading the file only if the DBMS isn't writing to the file or letting the DBMS handle its own backups.

Welbog
  • 59,154
  • 9
  • 110
  • 123
2

This is similar to this question:

Opening a file's Shadow Copy if the current copy is in use

It depends on how the database is opening the MDB file. If it's not allowing read sharing then you're out of luck unless you are able to open the shadow copy. There's a discussion on how to do this here:

How do I copy a file or folder that is locked under windows programmatically?

Community
  • 1
  • 1
Keltex
  • 26,220
  • 11
  • 79
  • 111