2011-09-01 129 views
3

我开到本地MySQL服务器,并在connection.Open()方法的方面,它抛出这个错误:为什么在MySQL中打开连接会引发分布式事务错误? (.NET连接器)

System.NotSupportedException: MySQL Connector/Net does not currently support distributed transactions.
at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction(Transaction> transaction) at 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服务器我连接到

+0

什么'ConfigurationManager.ConnectionStrings [“连接”]。ConnectionString'看起来像什么? (请在发布之前清理任何IP地址或密码) – Femi

+0

我使用连接字符串更新了上述 –

回答

9

尝试增加 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被混淆为认为存在某个其他数据库的现有事务。

+0

System.ArgumentException:不支持关键字。 参数名称:enlist at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ValidateKeyword ... –

+0

哈,关闭!这是'自动登记'。我在MySql.Data代码中打开了反射器并挖了一圈。更新您的答案,我会将其标记为已接受,谢谢! –