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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:43:34+00:00 2026-05-11T15:43:34+00:00

I have a stored procedure that looks something like: CREATE PROCEDURE my_procedure @val_1 INT,

  • 0

I have a stored procedure that looks something like:

 CREATE PROCEDURE my_procedure    @val_1 INT,   @val_2 INT AS SET NOCOUNT ON; SET XACT_ABORT ON;  BEGIN TRY   BEGIN TRANSACTION;    INSERT INTO table_1(col_1, col_2)   VALUES (@val_1, @val_2);      COMMIT TRANSACTION; END TRY BEGIN CATCH   IF @@TRANCOUNT > 0     ROLLBACK TRANSACTION;    DECLARE     @ERROR_SEVERITY INT,     @ERROR_STATE    INT,     @ERROR_NUMBER   INT,     @ERROR_LINE     INT,     @ERROR_MESSAGE  NVARCHAR(4000);    SELECT     @ERROR_SEVERITY = ERROR_SEVERITY(),     @ERROR_STATE    = ERROR_STATE(),     @ERROR_NUMBER   = ERROR_NUMBER(),     @ERROR_LINE     = ERROR_LINE(),     @ERROR_MESSAGE  = ERROR_MESSAGE();    RAISERROR('Msg %d,   Line %d,   :%s',     @ERROR_SEVERITY,     @ERROR_STATE,     @ERROR_NUMBER,     @ERROR_LINE,     @ERROR_MESSAGE); END CATCH 

When this code is executed through the database, everything runs correctly. When execute through ADO.NET I get back the following error message:

‘The INSERT statement conflicted with the FOREIGN KEY constraint ‘FK_table1_table2‘. The conflict occurred in database ‘my_database‘, table ‘dbo.table_1‘, column ‘col_1‘. Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0. ‘

Is this happening because the XACT_ABORT setting is forcing a transaction from ADO.NET to be rolled back? What’s the best way to go about avoiding this error?

  • 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. 2026-05-11T15:43:35+00:00Added an answer on May 11, 2026 at 3:43 pm

    you can check XACT_STATE() in your code and then commit or rollback, check it out here: Use XACT_STATE() To Check For Doomed Transactions

    basically something like this will blow up

    BEGIN TRANSACTION TranA     BEGIN TRY      DECLARE  @cond INT;      SET @cond =  'A';     END TRY     BEGIN CATCH      PRINT 'a'     END CATCH;     COMMIT TRAN TranA 

    and when you check xact_state you can control it

    BEGIN TRANSACTION TranA     BEGIN TRY      DECLARE  @cond INT;      SET @cond = 'A';     END TRY     BEGIN CATCH      PRINT ERROR_MESSAGE();     END CATCH;     IF XACT_STATE() =0     BEGIN      COMMIT TRAN TranA     END     ELSE     BEGIN      ROLLBACK TRAN TranA     END 

    Also take a look at these two must read links Implementing Error Handling with Stored Procedures and Error Handling in SQL Server – a Background.

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

Sidebar

Related Questions

I have a stored procedure that returns multiple resultsets, it looks something like this
I have an outdated stored procedure that looks something like: CASE WHEN (org.org_misc_data =
I have a line in my SQL Stored Procedure that looks like this (works
i have a stored procedure that has to retrieve data from multiple tables something
I have a piece of code that looks something like this (ClearImportTable and InsertPage
I have a stored procedure that takes a user ID and calculates their balance
I have a stored procedure that takes no parameters, and it returns two fields.
I have a stored procedure that I want to call from within another, and
I have a stored procedure that logs some data, how can I call this
i have a stored procedure that performs a join of TableB to TableA :

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.