Performing a Transaction in 2 systems

G

Guest

I have the need to perform an atomic operation in two systems, a database and
an ftp site. The process is two step; 1. insert a row into oracle, 2. delete
a file from a remote ftp site. I need to make these steps atomic...either
they both succeed or both fail. Any suggestions on how I create a
transaction that bridges these two steps (systems) using C#?

Thanks in advance!
 
N

Nicholas Paldino [.NET/C# MVP]

Chris,

The problem here is the FTP site. You will have to write some sort of
transaction management for this. Unfortunately, doing something of this
nature is rather tricky. For example, say you write the file to FTP, but
the database insert fails. Then you have to delete the file on the FTP
site. What if you do the reverse?

All-in-all, unless you have an existing resource manager for the FTP
site (which I doubt), then I would consider another option. There are too
many things to take into account (what if the network fails in the middle?
How can you roll back then? Things of that nature).

If you are really serious about doing this the proper way, I would look
into creating a resource manager for FTPing, and then use COM+ to handle the
transaction.

What would be more helpful was if there was a transaction manager on the
FTP machine you want to delete the file from. That way, you could get a
true distributed transaction.

Hope this helps.
 
C

Clemens Reijnen

Chris,

I don't think you can get this opperation atomic, you have to make some kind
of compensation code for it [just like biztalk long running transaction
compensation]. When one of the jobs fail there must be some custom rollback
code who rollsback the other actoins. And to be more sure that the actoins
will succeed you can write code wich checks if the operation will succeed,
if the file excists if the db is available and that kind of things... when
all checks give an ok, the code can preform the actions when one fails the
compensation code will be executed. At a gotodtnet workspace I've put some
code wich preforms that same steps to deploy and configurate a biztalk
solution... have a look.
http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=153aedcf-809f-4e6c-850a-9d13acfccc0a

greets Clemens
 
G

Guest

My suggestion is....

1. step 1 - insert row into oracle, do not perform commit
2. step 2 - delete the file from ftp site
3. if the file is deleted ok, send oracle commit, otherwise do not send
commit (which I would think this means the insert is removed???)

Although this is a simple solution, I don't think it will work since in step
3 if the ftp fails, it is too late to not send the commit since the record
has already auto-committed. I assume that once the process that does the
insert closes, an auto-commit occurs.

Another solution is to add a column that represents a transaction complete
flag which I will update once the ftp delete is complete. Once again, the
problem arises that the ftp delete works, then I can't update the flag since
the DB is unresponsive.

I thought I read somewhere that C# was going to support transactions in the
future??




Clemens Reijnen said:
Chris,

I don't think you can get this opperation atomic, you have to make some kind
of compensation code for it [just like biztalk long running transaction
compensation]. When one of the jobs fail there must be some custom rollback
code who rollsback the other actoins. And to be more sure that the actoins
will succeed you can write code wich checks if the operation will succeed,
if the file excists if the db is available and that kind of things... when
all checks give an ok, the code can preform the actions when one fails the
compensation code will be executed. At a gotodtnet workspace I've put some
code wich preforms that same steps to deploy and configurate a biztalk
solution... have a look.
http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=153aedcf-809f-4e6c-850a-9d13acfccc0a

greets Clemens


Chris Fink said:
I have the need to perform an atomic operation in two systems, a database
and
an ftp site. The process is two step; 1. insert a row into oracle, 2.
delete
a file from a remote ftp site. I need to make these steps atomic...either
they both succeed or both fail. Any suggestions on how I create a
transaction that bridges these two steps (systems) using C#?

Thanks in advance!
 
N

Nicholas Paldino [.NET/C# MVP]

Chris,

It does support transactions, in the sense that it provides a
transaction manager. However, that doesn't mean that everything just works
from that point on. What it really means is that if the resource is enabled
as transaction-enabled, then it can participate in the transaction.

In reality, you would need to have a transaction manager on the other
side, so that it can coordinate the transaction on the FTP site.

Also, you didn't take into consideration the situation when the commit
to the DB fails, and you have already deleted the file. You would have to
undelete it in order to make it truly atomic.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Chris Fink said:
My suggestion is....

1. step 1 - insert row into oracle, do not perform commit
2. step 2 - delete the file from ftp site
3. if the file is deleted ok, send oracle commit, otherwise do not send
commit (which I would think this means the insert is removed???)

Although this is a simple solution, I don't think it will work since in
step
3 if the ftp fails, it is too late to not send the commit since the record
has already auto-committed. I assume that once the process that does the
insert closes, an auto-commit occurs.

Another solution is to add a column that represents a transaction complete
flag which I will update once the ftp delete is complete. Once again, the
problem arises that the ftp delete works, then I can't update the flag
since
the DB is unresponsive.

I thought I read somewhere that C# was going to support transactions in
the
future??




Clemens Reijnen said:
Chris,

I don't think you can get this opperation atomic, you have to make some
kind
of compensation code for it [just like biztalk long running transaction
compensation]. When one of the jobs fail there must be some custom
rollback
code who rollsback the other actoins. And to be more sure that the
actoins
will succeed you can write code wich checks if the operation will
succeed,
if the file excists if the db is available and that kind of things...
when
all checks give an ok, the code can preform the actions when one fails
the
compensation code will be executed. At a gotodtnet workspace I've put
some
code wich preforms that same steps to deploy and configurate a biztalk
solution... have a look.
http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=153aedcf-809f-4e6c-850a-9d13acfccc0a

greets Clemens


Chris Fink said:
I have the need to perform an atomic operation in two systems, a
database
and
an ftp site. The process is two step; 1. insert a row into oracle, 2.
delete
a file from a remote ftp site. I need to make these steps
atomic...either
they both succeed or both fail. Any suggestions on how I create a
transaction that bridges these two steps (systems) using C#?

Thanks in advance!
 

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