SQLite.Net-PCL icon indicating copy to clipboard operation
SQLite.Net-PCL copied to clipboard

Need to delete the database completely, can I close the database or delete it from the API?

Open gtas-verisk opened this issue 9 years ago • 5 comments

I have a requirement of deleting the database when the logout action happens.

I can't seem to find any delete database method, and maybe that's OK but when manually try to delete the file with the path, it gives me an exception "readonly".

SQLite.Net.SQLiteException: ReadOnly
  at SQLite.Net.SQLiteCommand.ExecuteNonQuery () [0x000db] in <filename unknown>:0 
  at SQLite.Net.SQLiteConnection.Execute (System.String query, System.Object[] args) [0x00044] in <filename unknown>:0 
  at SQLite.Net.SQLiteConnection.Update (System.Object obj, System.Type objType) [0x00104] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---

Looks like it still is open executing a query.

Any ideas how to close and delete the database?

gtas-verisk avatar Dec 08 '15 17:12 gtas-verisk

Will dropping all of the tables be sufficient? I loop through and drop all of the tables and then call VACUUM to reclaim disk space.

valdetero avatar Jan 26 '16 15:01 valdetero

I have a similar problem with async connections. I need to open a stream from the db file to upload it to a server for backup. However, after the first access the db file is locked and trying to open a stream gives an access denied error. I need to close the connection, but I don't find any way of doing this, the SQLiteAsyncConnection doesn't have a Dispose() method AFAICS. Apologies if I'm missing something.

shinsenai avatar Mar 06 '16 17:03 shinsenai

@valdetero How do you call VACUUM to reclaim disk space? I use DeletaAll for each table and it will do the job.

xplatsolutions avatar Jun 13 '16 15:06 xplatsolutions

@xplatsolutions just write it as though you're writing a regular sql command. Get your instance of SQLiteConnection (or SQLiteConnectionWithLock) and execute: _db.Execute("VACUUM");

valdetero avatar Jun 13 '16 16:06 valdetero

Sounds about right, thanks.

xplatsolutions avatar Jun 13 '16 16:06 xplatsolutions