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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:17+00:00 2026-05-24T12:43:17+00:00

What is the problem with this code. It is giving this error The COMMIT

  • 0

What is the problem with this code.

It is giving this error The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. when some exception is coming in the procedure. How can I solve it?

    BEGIN 
    BEGIN TRANSACTION 
    DECLARE  
         @Id bigint 
        ,@Month nvarchar(100) 
        ,@Year nvarchar(100) 
        ,@CountryofExport nvarchar(100)
        ,@CountryofOrigin nvarchar(100) 
        ,@HSCode nvarchar(100)
        ,@Unit nvarchar(100)
        ,@Quantity nvarchar(100)
        ,@CustomValue nvarchar(255)
        ,@Type nvarchar(100)
        ,@TypeBit bit
        ,@CountryofExportID int
        ,@CountryofOriginID int
        ,@MeasurementId int
        ,@Remarks nvarchar(500)
        ,@CommodityId int
        ,@SDate nvarchar(100)
        ,@SameRec int
        ,@counts int


    DECLARE @Cursor_TradeFlow CURSOR
    SET @Cursor_TradeFlow = CURSOR FOR

    SELECT [Id],[Months],[Years],[CountryofExport],[CountryofOrigin],[HSCode],[Quantity],[Unit],[CustomValue],[Type] FROM [Temp_Trading]    

    OPEN @Cursor_TradeFlow
    FETCH NEXT FROM @Cursor_TradeFlow INTO @Id, @Month, @Year, @CountryofExport, @CountryofOrigin, @HSCode,@Quantity, @Unit, @CustomValue, @Type

    WHILE @@FETCH_STATUS = 0

    BEGIN
    Set @Remarks='';




   Declare @EICountry varchar(100),
   @Checkbit bit,
    @CheckYearIsNumeric bit,
    @CheckMonthIsNumeric bit


      BEGIN TRY        

         SET @CheckMonthIsNumeric= convert(INT, @Month);

      END TRY 

      BEGIN CATCH
    begin

             set @Checkbit=1;
         set @Remarks = @Remarks + 'Invalid Month'
         set @CheckMonthIsNumeric=1 
         end
      END CATCH



      BEGIN TRY

          set @CheckYearIsNumeric=  convert(INT, @Year);

      END TRY
      BEGIN CATCH


        SET @CheckYearIsNumeric= 1;
        set @Checkbit=1;
        set @Remarks = @Remarks + 'Invalid Year'

      END CATCH      


    Set @SameRec = (Select COUNT(*) From TradeFlow Where int_Month = @CheckMonthIsNumeric and int_Year = @CheckYearIsNumeric
                  and int_OriginLocationId = @CountryofExportID and int_DestinationLocationId = @CountryofOriginID and int_CommodityId = @CommodityId
                  and int_MeasurementId = @MeasurementId)   


    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
    END

    FETCH NEXT FROM @Cursor_TradeFlow INTO @Id, @Month, @Year, @CountryofExport, @CountryofOrigin, @HSCode,@Quantity, @Unit, @CustomValue, @Type

    END
    CLOSE @Cursor_TradeFlow
    DEALLOCATE @Cursor_TradeFlow
    COMMIT
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-24T12:43:18+00:00Added an answer on May 24, 2026 at 12:43 pm

    Having:

    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
    END
    

    inside a cursor loop is a bad sign – you rollback the transaction, and then continue into the next iteration. When the loop finally finishes, you attempt to commit and – Oops – there’s no open transaction any longer, and every operation after the rollback has been left in place.

    You might want to exit the loop after the rollback using a GOTO, or deal with the errors in a different way. It’s too hard to tell what the best strategy might be.

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

Sidebar

Related Questions

I am having some trouble with this code . The problem is when i
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have this code and it's giving me an undefined error if country is
So this Python problem has been giving me problems since I've tried refactoring the
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
This is an erlang problem, it seems. I have this code to test the
I am trying to convert this test code to C# and having a problem
I've got a problem with inheritance and generics. This is the code that illustrates
Expanding this question on how I learnt to pass from problem description to code
I'm trying to understand whay i get an error on this code: (the error

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.