Beat,
You are nesting transactions which I think are not supported by System.Data.SQLite
When you are within a transactionscope, don't start handling your own transactions with connection.BeginTransaction.
A connection that is opened within a transactionscope automatically enlists in the transaction of the transactionscope.
A BeginTransaction notices that there is already a transaction going on and doesn't do anything.
When you have an exception , the inner transaction is aborted and this aborts the whole transaction,
so when the transactionscope goes out-of-scope, there is no transaction going on anymore and thus you get the SQLiteException.
Your program should be like this :
using (var scope = new TransactionScope())
{
connection.Open();
SomeFuncWithException();
scope.Complete();
}
If you want to explicitly start a new transaction within a transactionscope,
you can do so by starting a new transactionscope with TransactionScopeOption.RequiresNew
before opening the connection like this :
using (var scope = new TransactionScope())
{
using (var scope2 = new TransactionScope(TransactionScopeOption.RequiresNew))
{
connection.Open();
SomeFuncWithException();
scope2.Complete();
}
scope.Complete();
}
Hope this helps.