All working fine but last week, I have tryed to make a Rollback transaction : it failed, the data are written into database.
The code is like :
Code: Select all
using (var scope = new System.Transactions.TransactionScope())
{
var codeVersion = new EntityCodesVersion();
codeVersion.DateImport = DateTime.Now;
codeVersion.Version = "8.0";
using (DatabaseManagerDbContext context = ADatabaseManagerFactory.Instance.CreateDatabaseManagerDbContext())
{
context.CodesVersions.Add(codeVersion);
bool bOKSave = context.SaveChanges() > 0;
}
scope.Complete();
}
- Editing postgresql.conf and activate option max_prepared_transactions to 5
- If I put PgSqlConnectionStringBuilder.Enlist = false :
When context.SaveChanges() is run, the EntityCodesVersion record is written into database. It should not be written into database because It is done into a TransactionScope scope !
So, the scope.Complete() done nothing more because the record is already written into database. - If I put PgSqlConnectionStringBuilder.Enlist = true : Two things :
- When open trigger on table notifications, I have exception :
Exception (TransactionAbordedException) The transaction has been interrupted.
1.inner Exception : cannot execute PREPARE on transaction that have execute LISTEN, UNLISTEN or NOTIFY. - When SaveChange is executed : the record is not written into database (normal way), when scope.Complete is executed, nothing is done (not normal, it must be written into database). When goes out of the transaction, an exception is raised : TransactionAbordedException with same error.
- When open trigger on table notifications, I have exception :
Blocked by this problem for 2 days, no way to make transaction work fine !
Because I'm using CodeFirst, I use several connection at the same time (always one new connection on each call of database providers when adding / removing / update record from/to the database.).
I read this topics but it don't help me :
http://stackoverflow.com/questions/2819 ... ransaction
http://forums.devart.com/viewtopic.php?f=3&t=31196
http://stackoverflow.com/questions/9343 ... connection
All worked fine for Oracle database...
Any idea ?
PS : Version = 7.4.543.0 / DbMonitor = 3.0.4
Database : PostgreSQL 9.4 + posgis.