udir
asked on
Active Records + transaction...
Hi,
I need to build a transaction using AR, I wrote :
public int DeleteFunc()
{
TransactionScope DelTran = new TransactionScope();
int res = 0;
try
{
//INSERT THE ROW INTO USERS
string DataGridInsertCommand = "INSERT INTO USERS SELECT * "
+ "FROM USERS "
+ "WHERE USERS .USERS_ID = 1" ;
Database DataGriddb = DatabaseFactory.CreateData base("conn ection");
DataGriddb.ExecuteNonQuery (CommandTy pe.Text, DataGridInsertCommand);
//DELETE THE ROW FROM USERS
string DataGridDeleteCommand = "DELETE FROM USERS "
+ "WHERE USERS.USERS _ID = 1" ;
Database DataGriddb1 = DatabaseFactory.CreateData base("conn ection");
res = DataGriddb1.ExecuteNonQuer y(CommandT ype.Text, DataGridDeleteCommand);
DelTran.VoteCommit();
}
catch (Exception ex)
{
DelTran.VoteRollBack();
}
return res;
}
But the rollBack doesn't works.
Whats wrong?
I need to build a transaction using AR, I wrote :
public int DeleteFunc()
{
TransactionScope DelTran = new TransactionScope();
int res = 0;
try
{
//INSERT THE ROW INTO USERS
string DataGridInsertCommand = "INSERT INTO USERS SELECT * "
+ "FROM USERS "
+ "WHERE USERS .USERS_ID = 1" ;
Database DataGriddb = DatabaseFactory.CreateData
DataGriddb.ExecuteNonQuery
//DELETE THE ROW FROM USERS
string DataGridDeleteCommand = "DELETE FROM USERS "
+ "WHERE USERS.USERS _ID = 1" ;
Database DataGriddb1 = DatabaseFactory.CreateData
res = DataGriddb1.ExecuteNonQuer
DelTran.VoteCommit();
}
catch (Exception ex)
{
DelTran.VoteRollBack();
}
return res;
}
But the rollBack doesn't works.
Whats wrong?
ASKER
Hi,
It is new for me (AR + transaction)
Can u give an example of how to use IDbTransaction?
Thanks
It is new for me (AR + transaction)
Can u give an example of how to use IDbTransaction?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Bob,
What i didn't found is how to implement the :
IDbTransaction transaction = connection.BeginTransactio n();
as i wrote, i use :
Database DataGriddb = DatabaseFactory.CreateData base("conn ection");
and the "connection" define (at the global.asax) like that :
try
{
configPath = ConfigurationManager.AppSe ttings["co nfigPath"] ;
source = new XmlConfigurationSource(con figPath);
ActiveRecordStarter.Initia lize(typeo f(USERS).A ssembly, source);
}
So, how can i implement that connection at the
IDbTransaction transaction = connection.BeginTransactio n();
Thanks
What i didn't found is how to implement the :
IDbTransaction transaction = connection.BeginTransactio
as i wrote, i use :
Database DataGriddb = DatabaseFactory.CreateData
and the "connection" define (at the global.asax) like that :
try
{
configPath = ConfigurationManager.AppSe
source = new XmlConfigurationSource(con
ActiveRecordStarter.Initia
}
So, how can i implement that connection at the
IDbTransaction transaction = connection.BeginTransactio
Thanks
2) Are you distributing transactions across different system types?
3) Seems like all you need is an IDbTransaction.
Bob