Check Contraint Bypassing CATCH block in Distributed Transaction

后端 未结 1 732
自闭症患者
自闭症患者 2021-01-27 11:11

I have a MSSSQL stored procedure performing a distributed transaction that looks like this:

SET XACT_ABORT ON;
SET NOCOUNT ON;

BEGIN TRY
  BEGIN DISTRIBUTED TRA         


        
相关标签:
1条回答
  • 2021-01-27 11:54

    Since the distributed transaction coordinator is handling this, when the transaction fails on the distributed part of the transaction, the DTC sends a message in the form of an attention, which stops your code from executing, and which the TRY/CATCH cannot process.

    SQL Server can detect on your end when you are trying to insert an incorrect data type into a table (even on a remote instance) but the constraint is processed on the linked server, which causes the attention to be sent to DTC and your TRY/CATCH to be ignored.

    For more information see the first "Note" section in the "Using TRY...CATCH in Transact-SQL" section of SQL Server 2008 Books Online, located at:

    http://msdn.microsoft.com/en-us/library/ms179296.aspx

    0 讨论(0)
提交回复
热议问题