Msdtc交易

时间:2009-01-20 06:52:54

标签: sql-server msdtc

我正在使用Linked server进行交易 示例

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)已取消分布式事务。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)