2009-01-20 69 views
1

我使用的鏈接服務器的交易
例如MSDTC事務

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='['[email protected]+']' 

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

回答

相關問題