[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

TransactionScope in C#

Hush

5/9/2008 8:21:00 AM

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
2 Answers

Marc Gravell

5/9/2008 8:43:00 AM

0

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

Chris Shepherd

5/12/2008 1:17:00 PM

0

Marc Gravell wrote:
> 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.