Problems with Transaction Scope

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Problems with Transaction Scope

Post by ies » Tue 09 Jun 2009 15:55

Hi,
I'm trying to use TransactionScope:

case 1: Not found
using (miContexto Context = new miContexto())
{
using (TransactionScope tran = new TransactionScope())
{

//step1 : this function returns a code
string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;
//step2 : insert many rows in Table1 table
foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}

Context.SaveChanges(false );

//step 3: this function uses the rows that are inserted in step 2, but it doesn't find data
string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;

tran.Complete();
Context.AcceptAllChanges();

}
}

case 2: found ok (it hasn't transaction control)

using (miContexto Context = new miContexto())
{


string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;

foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}

Context.SaveChanges();

string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;
}
}
________
COCAINE REHAB ADVICE
Last edited by ies on Thu 24 Feb 2011 06:05, edited 1 time in total.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 10 Jun 2009 10:46

The cause of the problem is the following. Context.AddTable1 and Context.F_Import2 are executed with different connection objects. Context.F_Import2 is involved before the changes are committed to the database. We will investigate the issue.

ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Post by ies » Tue 30 Jun 2009 15:51

Hi,

Anything new on this subject?
________
VAPIR NO2
Last edited by ies on Thu 24 Feb 2011 06:06, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 01 Jul 2009 12:46

Please try the following workaround:

Code: Select all

using (miContexto Context = new miContexto()) 
{ 
Context.Connection.Open();
using (TransactionScope tran = new TransactionScope()) 
{
Please don't forget to close the connection after it is not needed.
This code will make the context to use only one connection instance.
Please let me know if something goes wrong.

ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Post by ies » Mon 06 Jul 2009 09:45

Hi Andrey,

It doesn't work. I need to combine in 1 connection function imports with LINQ , ?it's possible with devart dotConnect for oracle?
________
Lamborghini Countach Specifications
Last edited by ies on Thu 24 Feb 2011 06:06, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 08 Jul 2009 13:26

Please either put the Context.Connection.Open() method call inside the TransactionScope using block, or call the Context.Connection.EnlistTransaction() method, like this:

Code: Select all

using (miContexto Context = new miContexto()) 
{ 
using (TransactionScope tran = new TransactionScope()) 
{
  Context.Connection.Open(); 
or like this:

Code: Select all

using (miContexto Context = new miContexto()) 
{ 
Context.Connection.Open(); 
using (TransactionScope tran = new TransactionScope()) 
{
  Context.Connection.EnlistTransaction(); 

ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Post by ies » Mon 13 Jul 2009 07:30

Hi Andrey,

When I put the Context.Connection.Open() method call inside the TransactionScope using block: ERROR

ORA-24756: la transacci?n no existe

My code:

using (cnnEF Context = new cnnEF())
{
using (TransactionScope tran = new TransactionScope())
{
Context.Connection.Open();
List lst = Context.GETPRUEBA(null).ToList();
________
No2 vaporizer
Last edited by ies on Thu 24 Feb 2011 06:06, edited 1 time in total.

ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Post by ies » Mon 13 Jul 2009 07:35

Hi Andrey,

I try to call Context.Connection.EnlistTransaction() method, but EnlistTransaction needs 1 argument Transaction and TransactionScope is not valid.

My code:

using (cnnEF Context = new cnnEF())
{
Context.Connection.Open();
using (TransactionScope tran = new TransactionScope())
{
Context.Connection.EnlistTransaction();
List lst = Context.GETPRUEBA(null).ToList();
________
Buy marijuana seeds
Last edited by ies on Thu 24 Feb 2011 06:06, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 13 Jul 2009 11:46

I have just tried to execute the following code sample with the new build (it will be available for our customers soon). Everything executes successfully, both select and insert commands were executed using the one connection.

Code: Select all

using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(1, 1, 1))) {
        using (Entities db = new Entities()) {
          db.Connection.Open();
          var query = from dept in db.DEPT
                      select dept;
          int counter = 0;
          foreach (DEPT d in query) {
            counter++;
          }
          DEPT de = new DEPT
          {
            DEPTNO = 28,
            DNAME = "TEST",
            LOC = "HERE"
          };
          db.AddObject("DEPT", de);
          db.SaveChanges();
          db.Connection.Close();
        }
        ts.Complete();
      }

ies
Posts: 26
Joined: Thu 26 Feb 2009 08:10

Post by ies » Mon 13 Jul 2009 12:19

Hi Andrey,

When is this new version be available??

With this new build can I insert rows using linq and modify them using function imports???

thanks,
________
ZX14 VS HAYABUSA
Last edited by ies on Thu 24 Feb 2011 06:06, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 15 Jul 2009 06:21

The new build is available.

Post Reply