MSDTC交易

发布于 2024-07-12 07:27:41 字数 1662 浏览 6 评论 0原文

我正在使用链接服务器进行事务
例如

Alter Proc [dbo].[usp_Select_TransferingDatasFromServerCheckingforExample]

@RserverName varchar(100), ----- Server Name  
@RUserid Varchar(100),     ----- server user id
@RPass Varchar(100),       ----- Server Password 
@DbName varchar(100)       ----- Server database    

As
Set nocount on
Set Xact_abort on
Declare @user varchar(100)
Declare @userID varchar(100)
Declare @Db Varchar(100)
Declare @Lserver varchar(100)
Select @Lserver = @@servername
Select @userID = suser_name()
Select @User=user
Exec('if exists(Select 1 From [Master].[' + @user + '].[sysservers] where srvname = ''' + @RserverName + ''') begin Exec sp_droplinkedsrvlogin ''' + @RserverName + ''',''' + @userID + ''' exec sp_dropserver ''' + @RserverName + ''' end ')

Set @RserverName='['+@RserverName+']'

BEGIN TRY
BEGIN TRANSACTION

Declare @ColumnList varchar(max)
Set @ColumnList = null
Select @ColumnList = case when @ColumnList is not null then @ColumnList + ',' + quotename(name) else quotename(name) end from syscolumns where id = object_id('bditm') order by colid
Set identity_insert Bditm on
Exec ('Insert Into Bditm ('+ @ColumnList +') Select * From '+ @RserverName + '.'+ @DbName + '.'+ @user + '.Bditm')
Set identity_insert Bditm off

Commit
Select 1 

End try
Begin catch
If (@@ERROR <> 0)
Begin  
    If @@trancount >0 
    Begin
        Rollback transaction
        Select 0
    END
End 
End Catch

Set @RserverName=replace(replace(@RserverName,'[',''),']','')

Exec sp_droplinkedsrvlogin  @RserverName,@userID
Exec sp_dropserver @RserverName

,这是发生的错误:
Microsoft 分布式事务协调器 (MS DTC) 已取消分布式事务。

I am using Linked server for Transaction
example

Alter Proc [dbo].[usp_Select_TransferingDatasFromServerCheckingforExample]

@RserverName varchar(100), ----- Server Name  
@RUserid Varchar(100),     ----- server user id
@RPass Varchar(100),       ----- Server Password 
@DbName varchar(100)       ----- Server database    

As
Set nocount on
Set Xact_abort on
Declare @user varchar(100)
Declare @userID varchar(100)
Declare @Db Varchar(100)
Declare @Lserver varchar(100)
Select @Lserver = @@servername
Select @userID = suser_name()
Select @User=user
Exec('if exists(Select 1 From [Master].[' + @user + '].[sysservers] where srvname = ''' + @RserverName + ''') begin Exec sp_droplinkedsrvlogin ''' + @RserverName + ''',''' + @userID + ''' exec sp_dropserver ''' + @RserverName + ''' end ')

Set @RserverName='['+@RserverName+']'

BEGIN TRY
BEGIN TRANSACTION

Declare @ColumnList varchar(max)
Set @ColumnList = null
Select @ColumnList = case when @ColumnList is not null then @ColumnList + ',' + quotename(name) else quotename(name) end from syscolumns where id = object_id('bditm') order by colid
Set identity_insert Bditm on
Exec ('Insert Into Bditm ('+ @ColumnList +') Select * From '+ @RserverName + '.'+ @DbName + '.'+ @user + '.Bditm')
Set identity_insert Bditm off

Commit
Select 1 

End try
Begin catch
If (@@ERROR <> 0)
Begin  
    If @@trancount >0 
    Begin
        Rollback transaction
        Select 0
    END
End 
End Catch

Set @RserverName=replace(replace(@RserverName,'[',''),']','')

Exec sp_droplinkedsrvlogin  @RserverName,@userID
Exec sp_dropserver @RserverName

this is the Error occured:
The Microsoft Distributed Transaction Coordinator (MS DTC) has canceled the distributed transaction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文