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 8391157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:11:10+00:00 2026-06-09T19:11:10+00:00

Question: I have this SQL script: DECLARE @in_TE_UID varchar(36) DECLARE @in_ZO_BETE_Sort int DECLARE @in_user

  • 0

Question: I have this SQL script:

DECLARE @in_TE_UID varchar(36) 
DECLARE @in_ZO_BETE_Sort int 
DECLARE @in_user int 


SET @in_TE_UID = '9f510440-8828-44ce-bbea-6bc866902262'
SET @in_ZO_BETE_Sort = 0 
SET @in_user = 12435

-- http://stackoverflow.com/questions/884334/tsql-try-catch-transaction-in-trigger
BEGIN TRANSACTION BeforeUpdate;
BEGIN TRY
    IF NOT EXISTS 
    (
        SELECT 1 FROM T_FMS_ZO_Benutzer_TeaserOrder 
        WHERE (T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_Status = 1) 
        AND (T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_BE_ID = @in_user) 
        AND 
        (
            T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_TE_UID = @in_TE_UID 
            OR 
            (
                @in_TE_UID IS NULL 
                AND 
                T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_TE_UID IS NULL 
            ) 
        )    
    )
    BEGIN
        INSERT INTO T_FMS_ZO_Benutzer_TeaserOrder 
        (
             ZO_BETE_UID
            ,ZO_BETE_BE_ID
            ,ZO_BETE_TE_UID
            ,ZO_BETE_Sort
            ,ZO_BETE_Status
        )
        VALUES
        (
             NEWID() --<ZO_BETE_UID, uniqueidentifier,>
            ,@in_user --<ZO_BETE_BE_ID, int,>
            ,@in_TE_UID --<ZO_BETE_TE_UID, uniqueidentifier,>
            ,@in_ZO_BETE_Sort --<ZO_BETE_Sort, int,>
            ,1 --<ZO_BETE_Status, int,>
        )
        ;
    END
    ELSE
    BEGIN

        UPDATE T_FMS_ZO_Benutzer_TeaserOrder  
            SET  ZO_BETE_Sort = @in_ZO_BETE_Sort 

        WHERE (T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_Status = 1) 
        AND (T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_BE_ID = @in_user) 
        AND 
        (
            T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_TE_UID = @in_TE_UID 
            OR 
            (
                @in_TE_UID IS NULL 
                AND 
                T_FMS_ZO_Benutzer_TeaserOrder.ZO_BETE_TE_UID IS NULL 
            ) 
        ) 
        ;

    END

END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION BeforeUpdate --RollBack in case of Error

    --RETURN


    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

    SELECT 
        @ErrorMessage = ERROR_MESSAGE(),
        @ErrorSeverity = ERROR_SEVERITY(),
        @ErrorState = ERROR_STATE();

    -- Use RAISERROR inside the CATCH block to return error
    -- information about the original error that caused
    -- execution to jump to the CATCH block.
    RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
    );
END CATCH

It runs fine when I run it once.

If afterwards I run a

SELECT * FROM T_FMS_ZO_Benutzer_TeaserOrder

then it timeouts.

If I add with (nolock) then it works.

If I look at the processes in SSMS, I see a locked select with LCK_M_S.

If I execute the same command in code, I always get this error:

Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1

So really, what’s wrong with this code ?

  • 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-06-09T19:11:11+00:00Added an answer on June 9, 2026 at 7:11 pm

    You haven’t put a COMMIT in your SQL anywhere. Presumably it should go just before the END TRY

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

Sidebar

Related Questions

I have this question in which I have a SQL Server Compact Edition database
In Microsoft SQL Server: I have seen this question several times, but can't see
I have a hopefully pretty simple question here. I'm converting some Access SQL script
I have been trying to figure out why this PL/SQL purge script runs slowly
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
This is a follow up from my previous question I have this code basically
Possible Duplicate: Check if a variable is empty Simple PHP question: I have this
I have this question, just in theory. I do some query results and there
I have this question because I am not familiar latest generation of MS VS
I have this question: How could I call a codebehind method from jquery? I

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.