TransactionScope in C#

  • Thread starter Thread starter Hush
  • Start date Start date
H

Hush

Hi

I would like to handle transaction in MsSql 2005 and Oracle both in the same
time, and i want to provide safe way in case when something goes wrong.
Databases installed on two different host, client have remote communication
with db.
Let's say i want insert simple record to table in MsSql, and then i want to
do similiar operation in Oracle, now if any of this operation failed then in
my case i don't want to insert this transaction.
I read a little bit about TransactionScope, i guess that this is the answer
for that problem.
using (TransactionScope ts = new TransactionScope())
{
try
{
//connect to mysql and try to insert record
//connect to oracle and try to insert record


ts.Complete();
} catch (...) {...}
}


My question is what happen when for example insert records was fine and
before calling method ts.Complete() something wrong happen with one of server
where database is running (shutdown, lack of power, etc) ?

Greets
Hush
 
I would hope that it gets rolled back at both servers - presumably as
part of the automatic recovery step for the one that died, and more
immediately for the survivor.

Marc
 
Marc said:
I would hope that it gets rolled back at both servers - presumably as
part of the automatic recovery step for the one that died, and more
immediately for the survivor.

This is what *should* happen in all cases, and if it didn't I would suggest
submitting a bug report.

To be completely certain, you could always test this out by putting a breakpoint
on your ts.Complete() line, and then shutting down your DB server when it breaks
on that line (after writing some records).

Chris.
 
Back
Top