473,466 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2307
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: anders_tung | last post by:
Hi, I have a procedure which will call 3 functions. First function will update a record. Second function will delete a record. Third function will insert a record. Each function will return...
3
by: level8 | last post by:
Hi, Everybody, I'm a Hungarian SQL user and I need a little help for SQL Server 7 ! I protect my table against bad data with a trigger. I use ROLLBACK and RAISERROR statement in this trigger....
2
by: mahajan.sanjeev | last post by:
I have two SQLConnection objects having the same connection string and two corresponding SQLCommand objects for each connection object. I am using SQLTransaction with the first SQLConnection object...
2
by: mahajan.sanjeev | last post by:
Hi, I am having problems with rollback using the SQLTransaction object. I am trying to insert records in two tables in a transaction. I want to rollback all the changes if any exception occurs...
6
by: Tor Heigre | last post by:
Hello While testing our code on DB2 we have encountered a difference in the behaviour of DB2Driver (com.ibm.db2.jcc.DB2Driver with driverType= 4) compared to the drivers offered by Oracle 9i and...
1
by: cheesey_toastie | last post by:
I have a long query which I have set off and would like to stop, and rename one of the tables used. My query is due to my lack of understanding of the underlying structure of MSSQL-Server... ...
2
by: Ian Boyd | last post by:
We're encountering a situation where we're encountering a deadlock, and someone's been made the deadlock victim. But after that, DB2 refuses to run any SQL, and instead we get the error message: ...
2
by: NarutoFanatic | last post by:
Hello, I'm having trouble using a transaction - rollback statement in sql. I can't seem to have the rollback executed during an error when i've altered a table to add a column with the same name...
5
by: keirnus | last post by:
Hello, I am using Datasheet view when displaying my data. The data are displayed in a "x,y" matrix wherein data can be directly edited in the Datasheet. Anything inputted in a certain cell...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.