Hi,
I have a pretty annoying problem when using transactions with the entityframework...
In my application, I'm using transactions as follows :
- when I connect to the database, I immediately begin a transaction
- when the user clicks "save", I commit the transaction and begin a new one
This way, changes made to the databases are only saved when the user wants to (similar to a document-editing application)
It was working fine when I was accessing the database directly, without the entity framework. But now, when I try to commit, I get the following error :
EntityException : The underlying provider failed on Commit.
InnerException : SQLiteException : SQLite error\r\ncannot commit transaction - SQL statements in progress
Apparently it means that there are open DataReaders (I managed to produce the same error when trying to commit on a connection with open readers).
My problem here is that I can't close those readers, since they are handled by the Entity Framework, and I have no access to them !
Is it a normal behaviour for EF to keep the readers open after reading the data ??
To make things clearer, here is a bit of code :
db = new DvdEntities(connectionString);
trx = db.Connection.BeginTransaction();
....
foreach(Movie m in db.Movies) // this opens a cursor in SQLite
{
// do something
}
...
// the user clicks "save"
trx.Commit(); // the exception happens here
trx = db.BeginTransaction();
Am I doing something wrong ? I know this is not exactly the usual way of using transactions, but I don't see why it doesn't work... Could it be a bug in the provider ?
Any help would be greatly appreciated :-)