I'm using the sqlite-net async API to code a Windows Phone app. While writing a unit test to make sure that my adapter to the sqlite-net API created the file properly, I noticed that the adapter continues holding onto the file handle even after it has gone out of scope.
The async connection class (SQLiteAsyncConnection
) does not support IDisposable
so I cannot manually dispose it. Looking at the source, it seems like the async API creates a connection, uses it and disposes it every time. However, when my test cleanup code attempts to delete the created test database, some other resource is still holding onto it.
On November 23rd 2015 they added a static method that does what Mikko Viitala suggested, So I just put the following in my dispose method.
SQLiteAsyncConnection.ResetPool();
I had the exact same problem in case where database was supposed to be sent via email for debugging/analyzing purposes. There was no way of doing that because connection is held.
You can go around this by modifying the sqlite-net implementation a bit.
On top of SQLiteAsync.cs
add following partial class declaration.
namespace SQLite
{
public partial class SQLiteAsyncConnection
{
public void ResetConnections()
{
SQLiteConnectionPool.Shared.Reset();
}
}
}
and then change access modifier of above Reset
method as public
.
In your application code just call <YourSQLiteAsyncConnection>.ResetConnections();
before deleting the DB file.
Then again, when testing you could create your database in memory so you don't have to delete it at all. You can achieve this by setting DatabasePath as ":memory:"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With