473,574 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ 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 2317
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**********@y ahoo.com> escribió en el mensaje
news:11******** **************@ g49g2000cwa.goo glegroups.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**********@ya hoo.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***@vk arlsen.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**********@y ahoo.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
10033
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 a zero if successful, otherwise return 1. My questions are
3
7522
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. Users can get my error message after manual input, but the stored procedure always cancel because of ROLLBACK. So the input program dont't have...
2
2044
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 but the second SQLConnection object does not have any SQLTransaction object. I am inserting some data using the two command objects. The problem...
2
2797
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 in any of the inserts. But the SQLTransaction object only rolls back the inserts that happen before an exception. All inserts after the exception go...
6
4835
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 Sybase SQL Anywhere 7. Our system contains code like this (java pseudocode) Connection con = <> con.setAutoCommit(false);
1
5727
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... So say and update updates TABLE_A and I stop it, whilst this transaction is rolling back I attempt to rename TABLE_A to TABLE_A_OLD and rename a...
2
10758
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: "Application must execute a rollback. The unit of work has already been rolled back in the database but other resource managers involved in this...
2
11929
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 (run the alter script twice on purpose to test the rollback). Somehow i got an error of the column should be unique (since the column already added...
5
9845
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 is directly updated to DB. I want to open the Form, input data but WILL NOT COMMIT then close the Form. If I open the same Form again, the data...
0
8058
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8241
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7820
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8100
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3742
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1061
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.