高分求教:在触发器中使用链接服务器的问题

pbsh 2012-07-25 05:18:18
在触发器中往链接服务器上的数据库中插入数据,一直不能正常执行,返回错误如下:

链接服务器"SMS_SERVER"的 OLE DB 访问接口 "SQLNCLI10" 返回了消息 "没有活动事务。"。
Msg 0, Level 11, State 0, Line 0
当前命令发生了严重错误。应放弃任何可能产生的结果。

说一下环境:
两台服务器都是Windows 2008+SQL SERVER 2008

分别属于不同的VLAN,中间有硬件防火墙做端口映射,135端口开放,相互之间可以通过Telnet IP 135测试。

两台服务器上的MSDTC服务都已经启动,使用NT AUTHORITY\NetworkService登录,允许读取和写入,不验证用户,XA事务已开启。

在两台服务器的Hosts文件中分别添加了2台服务器的IP和计算机名映射。

折腾两天了,求遇到过的朋友指教,万分感谢。


...全文
356 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
---涛声依旧--- 2014-08-09
  • 打赏
  • 举报
回复
个人觉得用触发器应该行不通,建议在程序中实现或用SSIS来实现
  • 打赏
  • 举报
回复
遇到这个问题 ,服务器不再同一个Vlan 网络说的所有的开启的都开启了 要是在本机没问题,在非服务器环境下的局域网(同一个VLan)也没问题,服务器就是没辙。
pbsh 2012-08-06
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]
Try this:
These are the steps followed by me.

1. Created Linked Server with the Server Type as SQL Server

A. provided the following in the security tab

i. Local Login
ii. Remote login
……
[/Quote]

谢谢你的回复.

Checked Enforce Distributed Transaction in the source server
under Server Properties -> Connections

没有找到这个项,是否Require distributed transactions for server to server communication?

另外,你提到i. Local Login,是否需要设置Mapping内容?
以学习为目的 2012-08-05
  • 打赏
  • 举报
回复
关注一下,把帖子顶起来
KevinLiu 2012-08-04
  • 打赏
  • 举报
回复
Try this:
These are the steps followed by me.

1. Created Linked Server with the Server Type as SQL Server

A. provided the following in the security tab

i. Local Login
ii. Remote login
iii. Remote Password
iv. Selected Be made using this security context option and
provided Remote Login & Remote Password

B. Provided the following in the server options

i. Checked data access
ii. Checked RPC In
iii. Checked RPC Out

2. Checked Enforce Distributed Transaction in the source server
under Server Properties -> Connections

3. Started Distributed Transaction Coordinator is both the servers
Enabled Network DTC Access under Control Panel -> Adminstrative
Tools -> Component Services -> Computers -> My Computer. Right
click My Computer and go to properties, Go to MSDTC. Click on
Security configuration. Check Network DTC Access, Allow Inbound
and Allow Outbound in both the source and target and restarted
both the server (I mean the server and not sql server)

4. Then executed the query. Before I executed the query, I did SET
XACT_ABORT ON


By the way, use linked server within trigger may have performance problem.
弘恩 2012-08-03
  • 打赏
  • 举报
回复

需要打开一些的服务参数的,一时想不起来了。

否则,事务中无法包括链接服务器;也就是说,事务不能在两个服务器中!
pbsh 2012-08-03
  • 打赏
  • 举报
回复
这个问题仍然没有解决,暂时用存储过程+作业解决了.

我觉得问题的原因可能在于不同VLAN之间的防火墙和不同Windows操作系统造成的兼容性问题。
天-笑 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
顶起来
[/Quote]
我也帮你顶,呵呵,我也想知道有没高人能解决呢
天-笑 2012-07-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
谢谢,我还是希望能解决这个分布式事务的问题,希望有这方面经验的朋友现身说法.
[/Quote]
关注,解决好了 也贴在帖子里,告诉我是怎么解决的吧,谢谢!!
pbsh 2012-07-25
  • 打赏
  • 举报
回复
谢谢,我还是希望能解决这个分布式事务的问题,希望有这方面经验的朋友现身说法.
天-笑 2012-07-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
感谢你的解答,由于牵涉到主从表,所以还是考虑写事务不安全.
这里的应用用触发器比较好了,存储过程不能保证实时性,考虑情况太多.
[/Quote]

那你就不要用 连接服务器了,自己写程序同步,或者写个CLR 存储过程也行
pbsh 2012-07-25
  • 打赏
  • 举报
回复
感谢你的解答,由于牵涉到主从表,所以还是考虑写事务不安全.
这里的应用用触发器比较好了,存储过程不能保证实时性,考虑情况太多.
天-笑 2012-07-25
  • 打赏
  • 举报
回复
你不要写 begin tran
pbsh 2012-07-25
  • 打赏
  • 举报
回复
存储过程中使用是相同的性质吧?
我在查询分析器中测试,普通Insert 语句在增加了事务语句后也不能正常执行。
天-笑 2012-07-25
  • 打赏
  • 举报
回复
触发器是隐式开启事务的,我以前也遇到过这个问题。
我放弃触发器的,改为存储过程,定期执行

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧