我不确定是否有人熟悉这个错误.
以下是SP中使用的链接服务器.
ALTER PROCEDURE [dbo].[USP_SEMI_NEW_Pepsi]
AS
BEGIN
SET NOCOUNT ON
SET XACT_ABORT ON
IF OBJECT_ID('dbo.SEMI_NEW_Pepsi', 'U') IS NOT NULL
DROP TABLE dbo.SEMI_NEW_Pepsi;
SELECT
Pepsi.APPID
,Pepsi.Action
,Pepsi.Brand
,ISNULL (BV.BaseID,'') BaseID
,isnull(cast(Pepsi.QuantityID as varchar(150)),'')QuantityID
INTO dbo.SEMI_NEW_Pepsi
FROM
dbo.PREP_NEW_Pepsi Pepsi
LEFT OUTER JOIN linkedserver.dbo.Quantity sub ON sub.QuantityID = Pepsi.SubQuantityID
INNER JOIN linkedserver.dbo.Base BV ON BV.BaseID = Pepsi.BaseID
WHERE CASE WHEN(
(BV.BaseID IS NULL AND Pepsi.BaseID > '')
(sub.QuantityID IS NULL AND Pepsi.QuantityID > '')
END
当我试图执行此操作时
执行[USP_SEMI_NEW_Pepsi]
我收到的错误如下所示.
Msg 3988, Level 16, State 1, Line 1 New transaction is not allowed
because there are other threads running in the session.
但是当我只执行这部分并且没有调用SP时,我没有收到任何错误.
SELECT
Pepsi.APPID
,Pepsi.Action
,Pepsi.Brand
,ISNULL (BV.BaseID,'') BaseID
,isnull(cast(Pepsi.QuantityID as varchar(150)),'')QuantityID
INTO dbo.SEMI_NEW_Pepsi
FROM
dbo.PREP_NEW_Pepsi Pepsi
LEFT OUTER JOIN linkedserver.dbo.Quantity sub ON sub.QuantityID =Pepsi.SubQuantityID
INNER JOIN linkedserver.dbo.Base BV ON BV.BaseID = Pepsi.BaseID
WHERE CASE WHEN(
(BV.BaseID IS NULL AND Pepsi.BaseID > '')
(sub.QuantityID IS NULL AND Pepsi.QuantityID > '')
这是运行绝对正常,没有给出任何错误,但通过SP调用同样的事情是抛出错误.
愿有人请帮我解决这个问题.
代码中使用的链接服务器
最佳答案 问题出现是因为:
>您运行分布式查询(由于使用了链接服务器).
> XACT_ABORT设置在您的过程中设置为ON.
如果只运行查询,则默认情况下XACT_ABORT设置为OFF,并且不会出现问题.
这是一个简短的article解释细节.解决方法是使用:
BEGIN DISTRIBUTED TRANSACTION <Distributed Query> COMMIT TRANSACTION
但是,我个人从来不需要使用它.