日期:2014-05-19  浏览次数:20594 次

菜鸟提问! trigger可不可以跨服务器访问操作啊 急!!!!!!
类似:
if   exists(select   WarehouseCode   from   [43.82.54.90].[slim].[dbo].[tblWarehouse]       where   WarehouseCode   =@WarehouseCode   AND   StorerKey=@StorerKey)
begin
  select   distinct     @EntityCode=EntityCode,   @DivisionCode=DivisionCode   FROM   [43.82.54.90].[slim].[dbo].[tblWarehouse]         where   WarehouseCode   =@WarehouseCode   AND   StorerKey=@StorerKey    
end
else   if   exists(select     WarehouseCode     from   [43.82.54.90].[slim].[dbo].[tblWarehouse]         where   WarehouseCode   =@WarehouseCode   )
begin
select   top   1   @EntityCode=EntityCode,   @DivisionCode=DivisionCode   FROM   [43.82.54.90].[slim].[dbo].[tblWarehouse]         where   WarehouseCode   =@WarehouseCode
insert   into   [43.82.54.90].[slim].[dbo].[tblWarehouse]       (WarehouseCode,DivisionCode,EntityCode,StorerKey,Priority,Address,ModifiedBy,ModifiedOn)   values(@WarehouseCode,@DivisionCode,@EntityCode,@StorerKey,1, 'Default   Adress ', 'Trigger ',getdate())
end

------解决方案--------------------

--建立连接服务器
EXEC sp_addlinkedserver
--要创建的链接服务器名称
--这里就用数据源作名称
'218.204.111.111,3342 ',
'SQL Server '
GO


--创建链接服务器上远程登录之间的映射
EXEC sp_addlinkedsrvlogin
'218.204.111.111,3342 ',
'false ',
NULL,
--远程服务器的登陆用户名
'zhangzhe ',
--远程服务器的登陆密码
'fish2231 '
go


--查询数据
select * from [218.204.253.131,3342].pubs.dbo.jobs
go