471,347 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

rollback code

Hi,

I have a piece of code that uploads a file and writes to a database.
Is there a way that if the upload of the file fails or the database
write fails, that the entire process can be rolled back, so that
neither was done.

Basically what I'm trying to do is kind of like a transaction in .net
but not exactly because its not all sql. I just want the entire
process to rollback to its original state if either the file upload or
the sql write fails.

Is there a code example online?

Thanks in advance.

:D

Dec 1 '05 #1
5 2231
Unless you do 2 things in 2 separate threads, just upload the file
first, then write to DB later. If either action goes wrong, rollback
the file upload action. The sql transaction will take care of rolling
back DB for you if uploading succeeded but updating DB failed.

Dec 1 '05 #2
Since database already support transactions, you can open a transaction,
execute the SQL statements, upload the file and the upload fails rollback
the transaction. Otherwise, commit the changes.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

<dm**********@yahoo.com> escribió en el mensaje
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,

I have a piece of code that uploads a file and writes to a database.
Is there a way that if the upload of the file fails or the database
write fails, that the entire process can be rolled back, so that
neither was done.

Basically what I'm trying to do is kind of like a transaction in .net
but not exactly because its not all sql. I just want the entire
process to rollback to its original state if either the file upload or
the sql write fails.

Is there a code example online?

Thanks in advance.

:D

Dec 1 '05 #3
dm**********@yahoo.com wrote:
Hi,

I have a piece of code that uploads a file and writes to a database.
Is there a way that if the upload of the file fails or the database
write fails, that the entire process can be rolled back, so that
neither was done.

<snip>

Transaction support is not supported in all systems. For instance, file
systems, file uploads/downloads, etc. is not transacted.

Instead you'll have to write code to react to the problems, for instance
by deleting the file you just uploaded, or similar.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Dec 1 '05 #4
how do you tell in c# that the file upload failed and if it did
rollback the transaction (if the transaction code is in sql stored
proc)?

How do I return the value of whether the tranaction has executed
properly to the code as well just in case I have to delete the file?

Thanks

:D

Dec 1 '05 #5
Hi dmalhotr2001,

Whenever I'm in the position in with trasactions are required but not
supported, I use a try construct.

Try all your actions but don't do them for real. If all succeeds do the
actions for real.

For instance uploading to multiple databases lets say a oracle and a sql
database.
Try the actions rollback by default. If all goes well (no errors) run the
actions again without the rollback.

In your case do the upload to a temp location, do the database actions and
rollback.
When both return without errors move the file to the real location and do
the databse actions again.

This is of course not as good as a transaction, but it increases the
likelyhood of a success.

Kind regards,
--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"dm**********@yahoo.com" wrote:
Hi,

I have a piece of code that uploads a file and writes to a database.
Is there a way that if the upload of the file fails or the database
write fails, that the entire process can be rolled back, so that
neither was done.

Basically what I'm trying to do is kind of like a transaction in .net
but not exactly because its not all sql. I just want the entire
process to rollback to its original state if either the file upload or
the sql write fails.

Is there a code example online?

Thanks in advance.

:D

Dec 7 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by anders_tung | last post: by
3 posts views Thread by level8 | last post: by
2 posts views Thread by mahajan.sanjeev | last post: by
2 posts views Thread by mahajan.sanjeev | last post: by
6 posts views Thread by Tor Heigre | last post: by
1 post views Thread by cheesey_toastie | last post: by
2 posts views Thread by Ian Boyd | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.