Page 1 of 1

Problems with Transaction Scope

Posted: Tue 09 Jun 2009 15:55
by ies
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

Posted: Wed 10 Jun 2009 10:46
by Shalex
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.

Posted: Tue 30 Jun 2009 15:51
by ies
Hi,

Anything new on this subject?
________
VAPIR NO2

Posted: Wed 01 Jul 2009 12:46
by AndreyR
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.

Posted: Mon 06 Jul 2009 09:45
by ies
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

Posted: Wed 08 Jul 2009 13:26
by AndreyR
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(); 

Posted: Mon 13 Jul 2009 07:30
by ies
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

Posted: Mon 13 Jul 2009 07:35
by ies
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

Posted: Mon 13 Jul 2009 11:46
by AndreyR
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();
      }

Posted: Mon 13 Jul 2009 12:19
by ies
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

Posted: Wed 15 Jul 2009 06:21
by AndreyR
The new build is available.