MySQL Connector/NET - 支持 Mono 下的事务

发布于 2024-09-25 21:23:43 字数 1027 浏览 4 评论 0原文

有谁知道如何让 MySQL 事务在 Mono 下工作?

我正在使用 MySQL Connector/NET(通过 Subsonic 3),它在 Microsoft .NET 下完美运行。然而最近我尝试在 Ubuntu 上的 Mono 下运行相同的站点,它几乎可以工作 - 除了我似乎无法让事务工作。

阅读 Mono/MySQL 站点后,并不清楚什么是支持的,什么是不支持的。

最初的问题是 NotImplementedExcetion ,其调用堆栈如下:

[System.NotImplementedException]: The requested feature is not implemented.

at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction) <0x00181> 
at MySql.Data.MySqlClient.MySqlConnection.Open () <0x00381> 
at SubSonic.DataProviders.DbDataProvider.CreateConnection (string) <0x00059> 
at SubSonic.DataProviders.DbDataProvider.CreateConnection () <0x00015>

MySQL 网站上有一些提及,这似乎表明 Mono 不支持使事务正常工作所需的基础设施。还有评论说,使用 CommittableTransaction 而不是 TransactionScope 时事务工作得很好。所以我尝试了一下,但得到了同样的例外。

MySQL 网站上的另一条评论建议使用 MONO 构建选项重建 MySQL 数据提供程序。我尝试过,该网站现在可以运行,但交易没有被使用 - 它们只是被禁用了。真的吗?

我很难相信交易不能在这种环境下工作,但找不到有效的例子。

单声道 2.6.7、MySQL 连接/NET 6.3.4、Subsonic 3、Ubuntu 10.10

Does anyone know how to get MySQL transactions working under Mono?

I'm using MySQL Connector/NET (via Subsonic 3) and it works perfectly under Microsoft .NET. Recently however I tried running the same site under Mono on Ubuntu and it almost works - except I can't seem to get transactions working.

Reading around the Mono/MySQL sites it's not exactly clear what is and isn't supported.

The original problem is a NotImplementedExcetion with call stack like this:

[System.NotImplementedException]: The requested feature is not implemented.

at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction) <0x00181> 
at MySql.Data.MySqlClient.MySqlConnection.Open () <0x00381> 
at SubSonic.DataProviders.DbDataProvider.CreateConnection (string) <0x00059> 
at SubSonic.DataProviders.DbDataProvider.CreateConnection () <0x00015>

There's a few mentions of this on the MySQL site which seem to point to Mono not supporting the required infrastructure to make transactions work. There's also a comment that transactions work fine when using CommittableTransaction rather than TransactionScope. So I tried that, but got the same exception.

Another comment on the MySQL site suggested rebuilding the MySQL data provider with the MONO build option. Which I tried and the site now works, but transactions aren't being used - they've been simply disabled. Really?

I find it hard to believe that transactions can't be made to work in this environment, but can't find a working example.

Mono 2.6.7, MySQL Connection/NET 6.3.4, Subsonic 3, Ubuntu 10.10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

左岸枫 2024-10-02 21:23:43

想通了。 TransactionScope 似乎不起作用。恢复到 DbConnection.BeginTransaction 效果很好。我在这里写了如何在 Subsonic 下执行此操作: http://www.toptensoftware.com/blog/posts/18/using-transactions-with-mono-mysql-and-subsonic

Figured it out. It's TransactionScope that doesn't seem to work. Reverting back to DbConnection.BeginTransaction works fine. I've written up how to do it under Subsonic here: http://www.toptensoftware.com/blog/posts/18/using-transactions-with-mono-mysql-and-subsonic

小女人ら 2024-10-02 21:23:43

我在 mono v.2.10.9 和 mysqlconnector v. 6.6.5 和 6.7.2-Beta 中也遇到了这个问题,我无法找到这个问题的解决方案,但现在我想通了。

首先,我获取了 mysqlconnector 的源代码并将它们添加到我的项目文件夹中。认为如果我直接用单声道编译连接器就会起作用,但事实并非如此。
然后我单步查看代码,发现 MySql.Data 项目的 Connection.cs 文件中的第 530 行有以下代码行:

#if !MONO && !CF && !RT
  Console.WriteLine("### Should not be here... ###");
  if (Transaction.Current != null && Settings.AutoEnlist)
    EnlistTransaction(Transaction.Current);
#endif

Console.WriteLine 由我添加,以尝试如果我使用单声道运行我的应用程序并且它出现,它是否也会出现。所以我评论了这一行,之后一切都正常了。

然而,真正的解决方案不应该是注释掉某些代码行。
为了解决这个问题,您必须定义“MONO”符号。
如果您使用 MonoDevelop,只需右键单击项目 MySql.Data 并选择编译器部分。在那里您会找到一个带有“定义符号”标签或类似内容的文本框。只需将新符号“MONO”添加到此文本框中即可。

I also had this problem with mono v.2.10.9 and mysqlconnector v. 6.6.5 and 6.7.2-Beta and I was unable to find a solution for this problem but now I figured it out.

First I took the sources of mysqlconnector and added them into my project folder. Thought it would work if I compile the connector directly with mono but it doesn't.
Then I stepped trough the code and I found that there are the following lines of code at line 530 in the file Connection.cs of the MySql.Data project:

#if !MONO && !CF && !RT
  Console.WriteLine("### Should not be here... ###");
  if (Transaction.Current != null && Settings.AutoEnlist)
    EnlistTransaction(Transaction.Current);
#endif

The Console.WriteLine was added by me to try if it will also appear if I run my Application with mono and it appeared. So I commented this lines out and after that everything was working at this moment.

The real solution however should not be to comment out some lines of code.
For solving this you have to define the 'MONO' symbol.
If you are using MonoDevelop just right click on the project MySql.Data and select the compiler section. There you will find a textbox with the label 'define symbols' or something similar. Simply add the new symbol 'MONO' into this textbox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文