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

Transaction not rolling back

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

calls 2nd stored procedure to proccess updates/inserts common to many
other stored procedures

does more various updates/inserts

commit

END

The problem I'm having is that within the 2nd stored procedure is that
if it encounters an error, it does not roll back the entire
transaction and I finish up with missing records in the database. Am
using this in the 2nd stored procedure:

if(@TypeId1 = @TypeId2 and @Line1 <'' and @Line2 <'')
begin
RAISERROR('error message', 16, 1)
RETURN
end

What could the problem be? From what I've read, it seems as though
you can't have an open transaction within one sp that calls another sp
and it maintains the same transactoin? Is this corrrect?

I tired the following too, and I still couldn't get it to work. Any
ideas anyone?

************ sp 1 ***********

Declare @AddressError char(3)

SET XACT_ABORT ON
BEGIN TRANSACTION

exec Sp2
@AddressError OUTPUT,
@variable1,
@variable2,
etc. etc

************** sp 2 *****************

@AddressError char(3) OUTPUT,

if(@TypeId1 = @TypeId2 and @Line1 <'' and @Line2 <'')
begin
RAISERROR('error message', 16, 1)
RETURN
end

SET XACT_ABORT ON
BEGIN TRANSACTION

process updates/inserts

Set @AddressError = 'no'
Commit

******** back to sp 1************

If @AddressError <'no'
BEGIN
rollback transaction
END

continue doing updates/inserts

commit

Mar 18 '07 #1
1 3502
On Mar 18, 2:49 pm, cricket...@gmail.com wrote:
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

calls 2nd stored procedure to proccess updates/inserts common to many
other stored procedures

does more various updates/inserts

commit

END

The problem I'm having is that within the 2nd stored procedure is that
if it encounters an error, it does not roll back the entire
transaction and I finish up with missing records in the database. Am
using this in the 2nd stored procedure:

if(@TypeId1 = @TypeId2 and @Line1 <'' and @Line2 <'')
begin
RAISERROR('error message', 16, 1)
RETURN
end

What could the problem be? From what I've read, it seems as though
you can't have an open transaction within one sp that calls another sp
and it maintains the same transactoin? Is this corrrect?

I tired the following too, and I still couldn't get it to work. Any
ideas anyone?

************ sp 1 ***********

Declare @AddressError char(3)

SET XACT_ABORT ON
BEGIN TRANSACTION

exec Sp2
@AddressError OUTPUT,
@variable1,
@variable2,
etc. etc

************** sp 2 *****************

@AddressError char(3) OUTPUT,

if(@TypeId1 = @TypeId2 and @Line1 <'' and @Line2 <'')
begin
RAISERROR('error message', 16, 1)
RETURN
end

SET XACT_ABORT ON
BEGIN TRANSACTION

process updates/inserts

Set @AddressError = 'no'
Commit

******** back to sp 1************

If @AddressError <'no'
BEGIN
rollback transaction
END

continue doing updates/inserts

commit
Your message is not clear about what error you have . If you are
referring to a table or column which is not in the database, no
rollback happens .

You can open a trasaction in one SP and call another SP . But make
sure that transaction should be as short as possible from execution
point of view .
You may encounter error in any one of the SPs at any time, you should
check for @@trancount 0 before executing COMMIT OR ROLLBACK
statements in both the SPs.

Mar 19 '07 #2

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

Similar topics

3
by: Alan | last post by:
Gidday people, I had a bit of a problem this morning. I think I've got it sorted now, but I wonder if anyone can shed some light. I have a plain VBS WHS file that instantiates a component that...
5
by: Jay Chan | last post by:
The transaction log in a database in our SQLSERVER-2000 server has grown to 16GB. I cannot shrink the transaction log manually because it says that the entire 16GB log size is not free. This is...
0
by: Mark Vuksani | last post by:
Hi, I have a trigger like this (simplified to illustrate the problem): -------- CREATE TRIGGER Test ON . FOR INSERT, UPDATE, DELETE AS RAISERROR( 'test trigger error !', 16, 1)
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? ...
6
by: Sri | last post by:
I am inserting records into a table - around 1 million records. I want to do the insert 10000 records at a time using TRAN. My insert statement is very simple: BEGIN TRAN T1 Insert INTO TABLE A...
1
by: REB | last post by:
If I create a transaction object for rolling back a insert query in the on click event of a form button can the transaction be tracked across other functions? For example: private void...
1
by: sreemati | last post by:
Hi Everyone, In brief, I am trying to get the whole block of code done in one go or not to do at all. Here is a piece of code I am trying: BEGIN TRANSACTION INSERT INTO authors...
6
by: qhjghz | last post by:
Hi All, The transaction isolation level for my stored procedure is READ COMMITTED. As far as I read, in this isolation level, "In effect, a SELECT query sees a snapshot of the database as...
3
by: Gordon | last post by:
I am currently working on some code for my CMS that creates a site folder, then creates all the necessary child folders inside it. The method that creates folders needs to insert into 2 tables so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.