Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 524677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:35:34+00:00 2026-05-13T08:35:34+00:00

so I created that(I used some stuff found on other website) to handle transactions

  • 0

so I created that(I used some stuff found on other website) to handle transactions and having a sort of stacktrace while executing stored procedure that could call other stored procedure that need transaction and etc.

so if I have A calling B and B is calling C and C got an error, I can correctly rollback my stuff and returning a stacktrace saying: error in C follow the trace to find out where/how/etc…

do any of you find a problem with this logic?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[NAME]
AS
BEGIN
    SET NOCOUNT ON
    SET XACT_ABORT ON

    declare @trancount int
    set @trancount = @@trancount
    declare @savePointName varchar(40)
    set @savePointName = newid()

    BEGIN TRY  
        if @trancount = 0
            begin transaction
        else
            save transaction @savePointName

        /*
        //  STUFF HERE
        */

        if @trancount = 0
            commit transaction
    END TRY  
    BEGIN CATCH
        declare  @xstate int
        set @xstate = XACT_STATE()
        if @xstate = -1  and @trancount = 0
            rollback transaction
        if @xstate = 1 and @trancount = 0
            rollback transaction
        if @xstate = 1 and @trancount > 0
            rollback transaction @savePointName

        declare @message varchar(max)
            set @message = ERROR_MESSAGE() + 
                       ' (' + ERROR_PROCEDURE() + 
                       ':' + ltrim(str(ERROR_LINE())) + 
                       ', Raised ' + ltrim(str(ERROR_NUMBER())) +
                       ', Severity ' + ltrim(str(ERROR_SEVERITY())) +
                       ', State ' + ltrim(str(ERROR_STATE())) + ')'

        RAISERROR(@message,16,1)
    END CATCH
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:35:35+00:00Added an answer on May 13, 2026 at 8:35 am

    No, I can’t spot anything wrong with this code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a form that is used for both adding and editing a
I have created a subclass of UITableViewController that is used as the custom class
I've used the reachability code provided by apple and created a UIAlert that displays
I have a NSMutableArray (called listOfSites) that is created and used in classA.m. I
I have created a procedure and used the below statement inside that . select
I have created a task for MSBuild that is to be used by developers
I write programs used internally by our company. I've created several support DLLs that
I have created one application in j2me, I have used json parsing in that
I have created an array of pointers. I have used some of them as
I have a source XML file that is used to create C# files that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.