473,386 Members | 1,745 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,386 software developers and data experts.

Transaction through stored Procedure

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 this thing to
be in a stored procedure. so that i have to write an execute statement
only on the ASP page and pass the parameters.

Looking forward for ur reply
DEEPAK
Jul 20 '05 #1
2 2345
On 7 Oct 2004 04:01:39 -0700, Deepak Mehta wrote:
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 this thing to
be in a stored procedure. so that i have to write an execute statement
only on the ASP page and pass the parameters.

Looking forward for ur reply
DEEPAK


Hi Deepak,

This is the rough outline of the procedure that will either execute all
statement or roll back everything. I'll leave it to you to fill in the
details (and improve the feedback on error).

CREATE PROC .....
AS
BEGIN TRANSACTION
UPDATE ..... -- first update
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN (99)
END
UPDATE ..... -- second update
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN (99)
END
COMMIT TRANSACTION
go

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
Hi Deepak,

The following structure is used to implement the transaction.

Begin Transaction
Try
{Statements]
Commit Transaction
Catch Exception
Rollback Transaction
End Try

The steps to complete a transaction including update of tables using a
stored procedure are listed below:

a.Open the connection.
b.Create a Transaction Object over the Connection Object by calling
its Begin Transaction method. The Begin Transaction method must be
called before performing any of the database operations that will take
part in the transaction.
c.Set Command Object's transaction property to the transaction object.
This will let ADO.Net to know which actions to do to undo when the
transaction is rolled back.
d.All the statements must be placed in the Try Clause of the exception
handler.
e.Set the Command Object's Command Text property to name of the stored
procedure.
f.Add parameters to the stored procedure. For each parameter, set its
name, type and value and add it to the Command Object's parameter
collection.
g.After all the parameters are set call the ExecuteNonQuery method of
the command object which will execute the stored procedure.
h.Commit the changes to the Tables by using Commit method.

I have explained this in detail in my book. However, thought of
posting it here.
Regards
Bharati
http://www.vkinfotek.com
Open source with a difference.
Jul 20 '05 #3

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

Similar topics

2
by: Sam | last post by:
Guys, I have a question regarding oracle. I have a stored procedure executing a number of statements including delete , select and lots of inserts in one big procedure and main transaction I...
1
by: Rittercorp | last post by:
I am debugging an app which blocks many processes in a SQL7 server DB. The app log writes every transaction "open" and "close". The weird thing is : when the app logfile says the transaction is...
11
by: harborboy76 | last post by:
Hi, I have a stored procedure that does a lot of INSERT/UDATE to 3 tables. And When I call the stored procedure, I get a Transaction Log Full error. When I want to do is turning off the...
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)...
2
by: Leon | last post by:
How can I code a stored procedure "within my codebehind page" that execute two or more stored procedures within a transaction? if so how would I pass values to each parameter? i.e. Begin Tran...
9
by: ucasesoftware | last post by:
i need to use this : Private Shared Sub Demo1() Dim db As SqlConnection = New SqlConnection("connstringhere") Dim transaction As SqlTransaction db.Open transaction = db.BeginTransaction Try...
2
by: kanda | last post by:
Hello. I am developing the application (VBA&ODBC, to be exact) which periodically calls the stored procedures in the IBM DB2. A few of the procedures require executing with isolation level RR (...
6
by: Crash | last post by:
C# VS 2003 ..Net Framework V1.1 SP1 SQL Server 2000 SP3 Enterprise Library June 2005 I'm working with some code {not of my creation} that performs the following sequence of actions: - Open...
1
by: cricketweb | last post by:
I have a stored procedure that calls another stored procedure with the first stored procedure opening a transaction: BEGIN SET XACT_ABORT ON BEGIN TRANSACTION does various updates/inserts
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.