SQLite.Net-PCL
SQLite.Net-PCL copied to clipboard
Need to delete the database completely, can I close the database or delete it from the API?
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?
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.
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.
@valdetero How do you call VACUUM to reclaim disk space? I use DeletaAll for each table and it will do the job.
@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");
Sounds about right, thanks.