博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

跨服务器触发器

Posted on 2010-08-05 17:23  大椰网吧  阅读(1189)  评论(0编辑  收藏  举报
exec sp_addlinkedserver   'ITSV', ' ', 'SQLOLEDB', 'SERVER2\SERVER2005'
exec sp_addlinkedsrvlogin  'ITSV', 'false',null,'sa','sa'

select * from ITSV.ZQ.dbo.resak

 

可以运用这条语句

Sql代码
  1. select * from  OPENDATASOURCE(  
  2.         'SQLOLEDB',  
  3.         'Data Source=192.168.18.103;User ID=sa;Password=111111'  
  4.         ).test.dbo.bbb  
 select * from  OPENDATASOURCE(          'SQLOLEDB',          'Data Source=192.168.18.103;User ID=sa;Password=111111'          ).test.dbo.bbb

 访问远端数据库中的内容,

 

当写入触发器时会报

Sql代码
  1. 消息 15281,级别 16,状态 1,第 1 行  
  2. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。  
消息 15281,级别 16,状态 1,第 1 行 SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。

 需要开启

Sql代码
  1. exec sp_configure 'show advanced options',1reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1reconfigure      
exec sp_configure 'show advanced options',1reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1reconfigure     

 关闭为

Sql代码
  1. exec sp_configure 'Ad Hoc Distributed Queries',0reconfigure exec sp_configure 'show advanced options',0reconfigure    
exec sp_configure 'Ad Hoc Distributed Queries',0reconfigure exec sp_configure 'show advanced options',0reconfigure   

 然后触发的时候会报

Sql代码
  1. 链接服务器"(null)"的 OLE DB 访问接口 "SQLNCLI10" 返回了消息 "该事务管理器已经禁止了它对远程/网络事务的支持。"。  
  2. 消息 7391,级别 16,状态 2,过程 ddd,第 15 行  
  3. 无法执行该操作,因为链接服务器 "(null)" 的 OLE DB 访问接口 "SQLNCLI10" 无法启动分布式事务。  
链接服务器"(null)"的 OLE DB 访问接口 "SQLNCLI10" 返回了消息 "该事务管理器已经禁止了它对远程/网络事务的支持。"。 消息 7391,级别 16,状态 2,过程 ddd,第 15 行 无法执行该操作,因为链接服务器 "(null)" 的 OLE DB 访问接口 "SQLNCLI10" 无法启动分布式事务。

 需要双放服务器同时打开msdtc服务    组件服务--》计算机--》我的电脑--》右键--》msdtc  进入设置 全勾上 注意不需要验证。