473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Transaction - how to?

Hi,

Just wondering...Suppose I have a couple of stored procedures that updates
some tables. How can I "wrap" these in a transaction that can be rolled back
in case of an error? I cant find any good documentation on the subject (I
assume I wanna use BEGIN TRANSACTION and COMMIT - or something similar.)

Perhaps theres even a way to automate this? In case of an error -> auto roll
back...:)

If say I have an SQL that says: "update table1 set field1=0 where id1=0".
How would that look if using transactions?

Also...any good links would be nice...:)

--
Pip

Jul 20 '05 #1
3 3339
PipHans wrote:
Perhaps theres even a way to automate this? In case of an error ->
auto roll back...:)


Just a thought...seems like connection.rollback cant be trusted (From
reading the Web). Would I in any case be better of just creating a stored
procedure that does the transactions?

Something like:

create procedure makeNM as
begin transaction

<update, whatever here>

if @@error <> 0 begin
rollback transaction
return -1
end
commit transaction
go

And then call this procedure from ASP...? Any thoughts?

--
Pip
Jul 20 '05 #2

"PipHans" <pi*****@hotmail.com> wrote in message
news:3f***********************@dtext02.news.tele.d k...
PipHans wrote:
Perhaps theres even a way to automate this? In case of an error ->
auto roll back...:)


Just a thought...seems like connection.rollback cant be trusted (From
reading the Web). Would I in any case be better of just creating a stored
procedure that does the transactions?

Something like:

create procedure makeNM as
begin transaction

<update, whatever here>

if @@error <> 0 begin
rollback transaction
return -1
end
commit transaction
go

And then call this procedure from ASP...? Any thoughts?

--
Pip


The stored procedure solution should work fine, along the lines of what
you've outlined above. Using a procedure in preference to ASP code is often
more efficient and secure. One point is that some negative return codes are
reserved for SQL Server (I think it's -1 to -99, but I'm not completely
sure), so most stored procedures are written to return 0 for success and >=1
for some error condition.

You should read up on transactions in Books Online, as it's a key area.
Also, since you need to check @@ERROR to decide if you need to roll back,
you need to know about error-handling in SQL, which is unfortunately rather
messy. This is a good source:

http://www.algonet.se/~sommar/error-handling-II.html

Simon
Jul 20 '05 #3
Simon Hayes wrote:
You should read up on transactions in Books Online, as it's a key
area. Also, since you need to check @@ERROR to decide if you need to
roll back, you need to know about error-handling in SQL, which is
unfortunately rather messy. This is a good source:


[Snip]

Thank you...Very nice.

--
regards,
Pip
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
10
by: TZoner | last post by:
1) Can one find the location of the 'Transaction Log' at: <Hard Disk>\Program Files\Microsoft SQL Server\MSSQL\Data\MyDb_Log.ldf? 2) Is it safe to delete it, as SQL will create a new Transaction...
3
by: Thiko | last post by:
Hi I take one nightly full database backup at 02:00 and backup the transaction log to one backup set every 15mins. The commands to do this are as follows and are set up to run as database...
2
by: Deepak Mehta | last post by:
i have to update two tables from ASP pages with same data but i want that both of them should be updated at one time. If either of them is not updated then my transaction should roll back.I want...
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
2
by: John Lee | last post by:
Hi, I have few questions related to .NET 2.0 TransactionScope class behavior: 1. Check Transaction.Current.TransactionInformation.DistributedIdentifier to identify if distributed transaction...
15
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried)...
1
by: Hubert Fröhlich | last post by:
Hi list, when doing a large Insert I get in the logfile: 2004-08-03 07:23:46 LOG: recycled transaction log file "000001BA000000BD" 2004-08-03 07:34:00 LOG: recycled transaction log file...
1
by: Matik | last post by:
Hi to all, Probably I'm just doing something stupid, but I would like you to tell me that (if it is so), and point the solution. There ist the thing: I' having a sp, where I call other sp...
2
by: Ryan Liu | last post by:
Hi, I have few db write and read to execute, so I use transaction. Is that a problem or is that a regular way that I only use transaction on some cmds only, and other cmds I do not use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.