简体   繁体   English

消息 7391:链接服务器无法开始分布式事务(两个 svs 都在本地运行)

[英]Msg 7391: linked server unable to begin a distributed transaction (both svrs running locally)

I setup a LinkedServer from SqlServer 2014 to MySQL 5.7.3 running on my Win 10 PC.我将 LinkedServer 从 SqlServer 2014 设置为在我的 Win 10 PC 上运行的 MySQL 5.7.3。 Both select & insert queries work fine alone via openquery, but the insert query won't function in a trigger.选择和插入查询都可以通过 openquery 单独工作,但插入查询在触发器中不起作用。 Please don't mark this as a duplicate unless you find a 'cure' that isn't already listed below!请不要将其标记为重复,除非您发现下面尚未列出的“治愈”!

OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[MySQL][ODBC 5.3(w) Driver]Optional feature not supported".链接服务器“MYSQL”的 OLE DB 提供程序“MSDASQL”返回消息“[MySQL][ODBC 5.3(w) 驱动程序]不支持可选功能”。

*Msg 7391, Level 16, State 2, Procedure TRG_AfterEventInsert, Line 14 *消息 7391,级别 16,状态 2,过程 TRG_AfterEventInsert,第 14 行

The operation could not be performed because OLE DB provider "MSDASQL" for linked server "MYSQL" was unable to begin a distributed transaction.由于链接服务器“MYSQL”的 OLE DB 提供程序“MSDASQL”无法开始分布式事务,因此无法执行该操作。

There are TONS of posts on this but I have done everything I can find and it still won't work.有很多关于这个的帖子,但我已经做了我能找到的一切,但它仍然不起作用。 I found a MS utility called dtcping which failed at first until I flipped a registry setting but now it succeeds.我发现了一个名为 dtcping 的 MS 实用程序,它起初失败,直到我翻转注册表设置,但现在它成功了。

On the DTC Properties screen I have enabled Network DTC Admin, allowed remote, allowed input/outbound without authentication and Enabled XA Transactions.在 DTC 属性屏幕上,我启用了网络 DTC 管理、允许远程、允许输入/出站而无需身份验证和启用 XA 事务。 On my linked server I have rpc & rpc out = true and "enable promotion of DT" false.在我的链接服务器上,我有 rpc & rpc out = true 和“启用 DT 升级”假。 I added the msdtc app into the firewall exclusions.我将 msdtc 应用程序添加到防火墙排除项中。

I also tried to disable DTC for my LinkedServer but that didn't work.我还尝试为我的 LinkedServer 禁用 DTC,但这没有用。 I still get the error.我仍然收到错误。

Can anyone suggest debugging measures here?任何人都可以在这里建议调试措施吗? I have spent almost a full day on this without success.我花了将近一整天的时间都没有成功。 MySQL driver is 5.3 (32bit). MySQL 驱动程序是 5.3(32 位)。

UPDATE: dtcPing runs without errors, but when I try the trigger insert I see the following in my dtctrace.log更新:dtcPing 运行没有错误,但是当我尝试触发器插入时,我在 dtctrace.log 中看到以下内容

TRANSACTION_BEGUN RM_ENLISTED_IN_TRANSACTION "resource manager #1001 enlisted as transaction enlistment #1. RM guid = '57c2b4b4-f37a-4017-a1fc-2d95bd64693d'" TRANSACTION_BEGUN RM_ENLISTED_IN_TRANSACTION "资源管理器 #1001 被登记为事务登记 #1。RM guid = '57c2b4b4-f37a-4017-a1fc-2d95bd64693d'"

RECEIVED_ABORT_REQUEST_FROM_BEGINNER "received request to abort the transaction from beginner" RECEIVED_ABORT_REQUEST_FROM_BEGINNER "收到初学者中止交易的请求"

TRANSACTION_ABORTING "transaction is aborting" TRANSACTION_ABORTING "交易正在中止"

Do you mean MySQL 5.3 ?你的意思是 MySQL 5.3 吗? The current manual shows versions as low as 5.7 and points that distributed transactions are only supported for the InnoDB storage engine 14.3.7 XA Transactions .当前手册显示版本低至 5.7 并指出分布式事务仅支持 InnoDB 存储引擎14.3.7 XA Transactions

Provided you have checked all about the MySQL part, have you checked with different kind of triggers on the SQL Server side?如果您已经检查了 MySQL 部分的所有内容,您是否检查了 SQL Server 端的不同类型的触发器? Are you perhaps using an unsupported data type?您是否使用了不受支持的数据类型?

"A distributed query that is wrapped in a trigger, even with no transaction explicitly specified, is also treated as a distributed transaction." “包含在触发器中的分布式查询,即使没有明确指定事务,也被视为分布式事务。”

support.microsoft.com/en-us/kb/274348 support.microsoft.com/en-us/kb/274348

So you need to use DTC OR use (2) from Calling linked server from trigger所以你需要使用 DTC OR use (2) from Calling links server from trigger

When you create trigger, use the following construct to avoid transactions:创建触发器时,请使用以下构造来避免事务:


create trigger ti on t for insert, update as
begin

    COMMIT -- Commit FIRST to avoid DTC...
    insert into  [mysql]...[mysql.customers] (a,b) -- Do you work
    select  i, 'Test'
    from    inserted
    BEGIN TRAN -- Start tran again otherwise it will crash!!
end
go

Note, the "[mysql]...[mysql.customers]" syntax, request Provider MSDASQL to have Level 0 only setting enabled (go to linked servers and set it on the provider).请注意,“[mysql]...[mysql.customers]”语法要求提供程序 MSDASQL 启用仅级别 0 设置(转到链接服务器并在提供程序上进行设置)。

But as other's suggested, you probably better of by just kicking a job from the trigger.但正如其他人所建议的那样,您可能最好只是从触发器中踢出一份工作。

Full test code:完整的测试代码:

---------------
-- Run on MYSQL...
---------------
CREATE TABLE customers (a INT, b CHAR (20), INDEX (a)) ENGINE=InnoDB;

---------------
-- Run on SQL Server
---------------
create table t (i int)

go

create trigger ti on t for insert, update as
begin

    COMMIT -- Commit tran to avoid DTC...
    insert into  [mysql]...[mysql.customers] (a,b)
    select  i, 'Test'
    from    inserted
    begin tran -- Start tran again otherwise it will crash!
end
go

insert into t (i) select 1

-- Verify results
select *
from [mysql]...[mysql.customers]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM