Problems with Transaction Scope
Problems with Transaction Scope
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
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.
Please try the following workaround:
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.
Code: Select all
using (miContexto Context = new miContexto())
{
Context.Connection.Open();
using (TransactionScope tran = new TransactionScope())
{
This code will make the context to use only one connection instance.
Please let me know if something goes wrong.
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
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.
Please either put the Context.Connection.Open() method call inside the TransactionScope using block, or call the Context.Connection.EnlistTransaction() method, like this:
or like this:
Code: Select all
using (miContexto Context = new miContexto())
{
using (TransactionScope tran = new TransactionScope())
{
Context.Connection.Open();
Code: Select all
using (miContexto Context = new miContexto())
{
Context.Connection.Open();
using (TransactionScope tran = new TransactionScope())
{
Context.Connection.EnlistTransaction();
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
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.
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
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.
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();
}
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
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.