I have problems releasing file access on the sqlite database file once the database was connected via dotconnect (I havent tried other sqlite drivers yet).
What i want to achieve is to connect to a database file, do some operations on it, then release the file access so the file can be moved/processed otherwise.
I have tried to dispose the sqlite database context before doing the operations on filesystem level, but i cant solve the "The process cannot access the file because it is being used by another process." error. The Sqlite database is set to run in exclusive access mode and my application is the only one working with it at that time (in my test environment).
My context wrapper has a dispose pattern implemented (similar to the one mentioned in http://ondotnet.com/pub/a/dotnet/2002/0 ... traps.html ). I am closing any open transactions/connections, then dispose the context.
Code: Select all
...
protected virtual void Dispose( bool disposing )
{
if ( !isDisposed ) // only dispose once!
{
if ( disposing )
{
if ( _sqliteContext.Transaction != null )
{
_sqliteContext.Transaction.Rollback();
_sqliteContext.Transaction.Dispose();
}
if ( _sqliteContext.Connection != null )
{
_sqliteContext.Connection.Close();
_sqliteContext.Connection.Dispose();
}
_sqliteContext.Dispose();
}
}
this.isDisposed = true;
}
public void Dispose()
{
Dispose( true );
GC.SuppressFinalize( this );
}
~SQLiteManager()
{
Dispose( false );
}