SQLiteDatabase.Backup vs FolderItem.CopyTo to backup database file?

Hi,

This may be a silly question, but here goes:

My project uses an sqlitedatabase, where the .DatabaseFile = SpecialFolder.ApplicationData.Child(“AppName”).Child(“UserData.db”)

I have functionality to allow the user to create a backup of that file, adapted from the example code in the SQLiteDatabase.Backup documentation, which works fine.

I was just wondering, what would be the difference if I instead simply used FolderItem.CopyTo to copy that file to a backup destination? At the time of running the code, the user would be connected to the database. Would that cause a problem?

I have no reason to need to change my current code, but I’m just curious why a specific Database.Backup method is needed. I assume it must be important in more complex scenarios, like multiple users connected to the same database or an in memory database…

Thanks,
Frank

To use CopyTo() you must be the only one using it, assure that you have no pending operations, and close it before proceeding. If you can’t reach such conditions, don’t do it, you are putting your DB copy at risk.

2 Likes

Thanks Rick. Exactly the type of confirmation I was looking for :+1:t3:

1 Like