473,800 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql server transaction syntax help

Hi,

I have an issue with my query.

1. I have 1 stored proc which have execution calls to multiple stored
procs within it.

2. I want to wrap that main stored proc in the transaction and rollback
if there are errors execution calls to other stored procs. I don't
believe my code is accounting for errors occuring in the execution
statement to other stored proc.

3. Is there an easy way to do this without creating tranaction on each
stored proc and returning the error code? How do I make this happen?
Below is the code.

Thanks

:D
ALTER procedure spAG_Add_Produc t
@prodCost money,
@prodWeight decimal,
@prodDesc nvarchar(100),
@prodName nvarchar(50),
@prodSize nvarchar(100),
@pic_filename nvarchar(50),
@userId int,
@exhib_id int
AS

declare @auth_Logic_id int
declare @intErrorCode int
BEGIN TRAN

SELECT @auth_Logic_id= AG_Auth_Logic.A uth_Logic_ID FROM
AG_Auth_Logic
INNER JOIN AG_Base_Active_ State ON AG_Auth_Logic.B ase_Active_Stat e_ID
= AG_Base_Active_ State.Base_Acti ve_State_ID
WHERE AG_Auth_Logic.A ction_Descripti on LIKE N'%category%'
AND AG_Base_Active_ State.Is_Alive = 1

INSERT INTO AG_Individual_P roduct
(
Product_cost,
Product_weight,
Product_descrip tion,
Product_name,
User_ID,
Auth_Logic_Id,
Product_size
)
VALUES (
@prodCost,
@prodWeight,
@prodDesc,
@prodName,
@userId,
@auth_Logic_id,
@prodSize
)

declare @prod_id int
select @prod_id = Scope_identity( )

-- add to pic table
declare @pic_id_out int
exec spAG_Add_Pictur e @pic_filename,
@prodName, @pic_id = @pic_id_out output

declare @prod_pic_out int
-- add to product_pic table
exec spAG_Add_Produc t_Picture @pic_id_out,
@prod_id, @prod_pic_id = @prod_pic_out output

-- add to product_pic_in_ exhib
exec spAG_Add_Produc t_Picture_in_Ex hibition @prod_pic_out,
@exhib_id, @prod_id

select @prod_id

SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRAN

PROBLEM:
IF (@intErrorCode <> 0) BEGIN
ROLLBACK TRAN
END

Jul 23 '05 #1
1 3932

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

Similar topics

2
13055
by: Anjula | last post by:
I have a stored procedure that takes 18 hours to complete. Sometimes I get the below error message when I run the stored procedure. 'Server : Msg 9002, Level 17, State 6, Line 1 The log file for database 'Customer' is full. Back up the transaction log for the database to free up some log space.'. I checked my log file and it is not full. And I don't know why I am getting this message. Any help is appreciated.
12
10033
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the process has been, from the site (in ASP), to: - select the top record from the members table where the assigned flag
0
2605
by: Raja | last post by:
I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle Database. The Link is perfect and dont have any problems in accessing the data from SQL Server 2000. The only problem i am facing is when i am trying to initiate a Distributed transaction. A simple Insert Query is working fine but when i try to perform the same through a Stored Procedure having the Begin Transaction i am getting the error mentioned below. Server:...
1
3737
by: dschneiderman | last post by:
Hello All, I am not a SQL Server expert, but I have been put in a pretty precarious situtation and I am close to panicking :( I have need to restore a SQL database from backup (through Enterprise Manager). The database got corrupt and I detached it, then was unable to attach it again. I created a new database with the same name and file names to restore to. When I go to All Tasks, restore, and restore from a previously run full...
4
6475
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to define the servername / hostname in my Perl Progrem.. Here is the code:
3
2789
by: RayPower | last post by:
I'm having a system using Access 2000 as both front-end (queries, forms, reports & temp tables for reports) & back-end (data) with back-end running on the server. The application runs on the network with around 15 users. The back-end database is suffering from performance issues. There were several corruptions since few months & one major corruption & corrupted the MSysObjects table. Also, the system will run batch process that generate...
2
6971
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
19
3355
by: dunleav1 | last post by:
I built a test job that loads data into the database. I get great performance with Oracle and I'm trying to tune Sql Server to get the same type of performance. Based on system monitoring it looks like an I/O issue. So I started investigating based on sql server perfromance tuning technical reference. Here are my system monitor findings: The system monitor shows during my job:
1
1978
by: toori | last post by:
i am new to the JAVA...Any one help to make codes for this server client application program "Design and implement a server application which acts as an Internet bank, i.e. keeps track of bank accounts and allows clients to connect over the Internet and make deposits and withdrawals from any of the bank accounts. Also implement the client application. Use any port number available for general use, i.e. in the range 50000 through 65535"...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.