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

  • Home
  • SEARCH
  • 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 779479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:55:59+00:00 2026-05-14T19:55:59+00:00

I have next block in the end of each my stored procedure for SQL

  • 0

I have next block in the end of each my stored procedure for SQL Server 2008

BEGIN TRY
    BEGIN TRAN
        -- my code
    COMMIT
END TRY
BEGIN CATCH
    IF (@@trancount > 0)
    BEGIN
        ROLLBACK
        DECLARE @message NVARCHAR(MAX)
        DECLARE @state INT
        SELECT @message = ERROR_MESSAGE(), @state = ERROR_STATE()
        RAISERROR (@message, 11, @state)
    END
END CATCH

Is it possible to switch CATCH-block to

BEGIN CATCH
    ROLLBACK
    DECLARE @message NVARCHAR(MAX)
    DECLARE @state INT
    SELECT @message = ERROR_MESSAGE(), @state = ERROR_STATE()
    RAISERROR (@message, 11, @state)
END CATCH

or just

BEGIN CATCH
    ROLLBACK
END CATCH

?

  • 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-14T19:55:59+00:00Added an answer on May 14, 2026 at 7:55 pm

    Actually, I never start a new transaction if I’m already in one.

    This deals with nested stored procs, distributed TXNs and TransactionScope

    Remember, there is no such thing as a nested transaction in SQL Server anyway.

    DECLARE @StartTranCount int
    
    BEGIN TRY
        SET @StartTranCount = @@TRANCOUNT
        IF @StartTranCount = 0 BEGIN TRAN
            -- my code
        IF @StartTranCount = 0 COMMIT TRAN
    END TRY
    BEGIN CATCH
        IF @StartTranCount = 0 AND @@trancount > 0
        BEGIN
            ROLLBACK TRAN
            DECLARE @message NVARCHAR(MAX)
            DECLARE @state INT
            SELECT @message = ERROR_MESSAGE(), @state = ERROR_STATE()
            RAISERROR (@message, 11, @state)
        END
        /*
        or just
        IF @StartTranCount = 0 AND @@trancount  
            ROLLBACK TRAN
        */
    END CATCH
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple block of code. Sub Run(Name) on error resume next
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
I have a block of code that looks like this: def create_page_object(url) begin page
I have next 2 blocks of code: def replace_re(text): start = time.time() new_text =
I have next code: int main() { OwnSelect(23, FD_READ | FD_WRITE); // <---- Several
Lets say i have this - for() { //this is a for-each loop try
I have a text file with structured data. After each text block it says
I have next command in my batch script dir project\*.java /s /B > temp_file
I have next interface public interface IMyInterface { string this[string key] { get; set;

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.