TransactionScope in C#

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
 
M

Marc Gravell

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
 
C

Chris Shepherd

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top