Page 1 of 1
dbMonitor and TransactionScope issue
Posted: Wed 28 Jul 2010 15:57
by mservidio
Hi All -
I am using Entity Framework to do some inserts/updates into my database. When I create new Entity Objects and then call SaveChanges(), everything works and dbMonitor shows all of the executed commands. However, when I wrap this same code in a TransactionScope, none of the db activity is showing the dbMonitor. Does anyone know why this is happening, and how to get dbMonitor to show this?
thanks,
Mark
Posted: Fri 30 Jul 2010 11:56
by AndreyR
I have just made a test and the SQL statements sent to database were correct.
I am using the latest 5.70.152 build of dotConnect for Oracle and DBMonitor 3.0.2. Here is the code I was using to reproduce the problem.
Could you please make changes in my code to reproduce the problem and post the changed code here?
Code: Select all
OracleMonitor mon = new OracleMonitor();
mon.TraceEvent += new Devart.Common.MonitorEventHandler(mon_TraceEvent);
mon.IsActive = true;
using (DataModel1Entities db = new DataModel1Entities()) {
using (TransactionScope t = new TransactionScope()) {
Dept d = new Dept
{
Deptno = 1,
Dname = "montest",
Loc = "montest"
};
db.AddToDepts(d);
db.SaveChanges();
t.Complete();
}
}
Posted: Fri 30 Jul 2010 15:29
by mservidio
Previously I had created the OracleMonitor within the Initialization constructor for my Entities. With the dbMonitor created there, the dbMonitor was working for and showing all calls to the db, except it wasn't showing any commands sent to the db that were within a transactionscope.
I've moved the created of the OracleMonitor to within the method that has the transactionscope, and now the dbMonitor shows the activity.
One further question on this though, while I don't see an explicit transaction in the dbMonitor, when I wrap my code in a TransactionScope, does DevArt provider automatically create a transaction in oracle? Ie: if an exception is thrown in my code before getting to t.Complete(), should the transaction commit/rollback?
Posted: Fri 30 Jul 2010 16:26
by AndreyR
Glad to hear the issue is resolved.
As for your question, the distributed transaction is created in Oracle server, and it is rolled back in case it is not completed before the Dispose method is called on the TransactionScope instance.
Posted: Fri 30 Jul 2010 16:39
by mservidio
Excellent. Thanks for the quick response!