【问题标题】:Why does opening a connection throw a distributed transactions error in MySQL? (.NET Connector)为什么在 MySQL 中打开连接会引发分布式事务错误? (.NET 连接器)
【发布时间】:2011-11-08 02:34:11
【问题描述】:

我正在打开与本地 MySQL 服务器的连接,在 connection.Open() 方法上它会抛出此错误:

System.NotSupportedException:MySQL 连接器/网络当前不支持分布式事务。
在 MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction(事务> 事务) 在 MySql.Data.MySqlClient.MySqlConnection.Open()

我正在做的就是:

var connection = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
connection.Open();

app.config中的连接字符串是

<add name="Connection" connectionString="server=localhost;user id=userid;Password=password;database=dbname" providerName="MySql.Data.MySqlClient" />    

我不知道它为什么要尝试登记事务,我没有指定任何事务并且我只有一个 MySQL 服务器要连接

【问题讨论】:

  • ConfigurationManager.ConnectionStrings["Connection"].ConnectionString 看起来像什么? (请在发布前清理任何 IP 地址或密码)
  • 我已经在上面更新了连接字符串

标签: .net mysql mysql.data


【解决方案1】:

尝试将Enlist=false 添加到您的连接字符串中:

编辑:来自MySQL Connector/.NET documentation,如果您在连接字符串中设置AutoEnlist=false,它应该可以工作。

<add name="Connection" connectionString="server=localhost;user id=userid;Password=password;database=dbname;AutoEnlist=false" providerName="MySql.Data.MySqlClient" />    

似乎某些版本的 ADO.NET 可以默认自动将连接登记到现有事务中。有关更多详细信息,请参阅http://msdn.microsoft.com/en-us/library/ms254973.aspx,但我预计 ADO 会在某个地方感到困惑,认为有一个现有事务正在进行到其他数据库。

【讨论】:

  • System.ArgumentException:不支持关键字。参数名称:在 MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ValidateKeyword 处登记...
  • 哈,结束!这是“自动登记”。我破解了打开的 Reflector 并在 MySql.Data 代码中进行了挖掘。更新您的答案,我会将其标记为已接受,谢谢!
猜你喜欢
  • 2021-07-30
  • 2014-12-18
  • 2011-12-24
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 2014-07-24
  • 2013-11-29
相关资源
最近更新 更多