我正在研究SQL Server 2008,我正在尝试执行一个存储过程来更新表并在链接服务器上执行另一个存储过程。
关键是它在没有更新时有效,就像这样:
[服务器1]上的[test_DTC]
CREATE PROCEDURE [dbo].[test_DTC]
@UserId int,
@Status tinyint
AS
BEGIN
EXEC [Server2].[Database].[dbo].[test_DTC];
END
GO
[Server2]上的[test_DTC]
CREATE PROCEDURE [dbo].[test_DTC]
AS
BEGIN
PRINT 'Done'
END
GO
在Server1上执行:
EXEC [test_DTC]
结果:
Done
但是当我在Server1过程中包含UPDATE时,它会失败。
[服务器1]上的[test_DTC]
CREATE PROCEDURE [dbo].[test_DTC]
@UserId int,
@Status tinyint
AS
BEGIN
UPDATE
Users
SET
Status=@Status
WHERE
UserId=@UserId;
EXEC [Server2].[Database].[dbo].[test_DTC];
END
GO
[Server2]上的[test_DTC]
CREATE PROCEDURE [dbo].[test_DTC]
AS
BEGIN
PRINT 'Done'
END
GO
在Server1上执行:
EXEC [test_DTC]
结果
Provider OLE DB "SQLNCLI10" from linked server "[Server2]" returned message "The transaction has already been implicitly or explicitly committed". Msg 7391, Level16, State 2, Procedure [Server2].[Database].[dbo].[test_DTC], Line 19
The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "Server2" was unable to begin a distributed transaction.
感谢您的帮助
答案 0 :(得分:1)
我找到了一个解决方案MSDN Blog
它说
原因是当事务从一台机器传播到另一台机器时,它们包括它们的机器名称/ DNS名称。当它到达另一台机器时,它将使用此名称尝试与发起者机器进行通信。如果此通信失败,则分布式事务将无法在系统中运行。
Microsoft在同一个
上提供了Detailed Article