This project is read-only.

How to Close/Disconnect database?

Nov 25, 2013 at 2:27 PM

what is the correct way to close/disconnect a database connection? I would like to create a copy of the database file to create a backup. But this is not possible as long the database is in use. Thus creating a backup means:
  1. Disconnect
  2. Copy
  3. Re-connect
Connecting to the database file is no problem:

database = new Database(ApplicationData.Current.LocalFolder, databaseName);
await database.OpenAsync();

But how can I close this connection again? Setting the database object to null does not work.
Nov 25, 2013 at 3:06 PM

Simply call the Dispose() method of your database instance.

Nov 26, 2013 at 1:07 PM
Thank you for your feedback. I already tried this, but unfortunately this does not work either. I encounter the same problem when deleting a database file:

database = null;

IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
if (isolatedStorage.FileExists(dbPath)) {

// OR

isolatedStorage.MoveFile(dbPath, trashPath);

Both operations (delete or move) result in an exception:
Delete: System.IO.IsolatedStorage.IsolatedStorageException: Unable to delete file. HResult -2146233264
Move: System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted. HResult -2146233264