MySQL Connector/NET - 支持 Mono 下的事务
有谁知道如何让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了。 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
我在 mono v.2.10.9 和
mysqlconnector
v. 6.6.5 和 6.7.2-Beta 中也遇到了这个问题,我无法找到这个问题的解决方案,但现在我想通了。首先,我获取了 mysqlconnector 的源代码并将它们添加到我的项目文件夹中。认为如果我直接用单声道编译连接器就会起作用,但事实并非如此。
然后我单步查看代码,发现 MySql.Data 项目的
Connection.cs
文件中的第 530 行有以下代码行: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: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.