开发者

MySQL Connector/NET - support for transactions under Mono

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.开发者_Go百科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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜