i am updating/inserting/deleting values on more than 1 database and want to implement a transaction.
currently its done like
try{
db[1].begintransaction();
db[1].ExecuteNonQuery();
db[2].begintransaction();
db[2].ExecuteNonQuery();
...
db[N].begintransaction();
db[N].ExecuteNonQuery();
// will execute only if no exception raised during the process
for (int a = 0; a < N; a++)
{
db[a].Commit();// what if there is an error/exception here
}
}
catch {
for (int a = 0; a < N; a++)
{
db[a].RollBack();
}
}
problem is it would fail horribly when there is an exception during commit (see the comment). any better idea?