Feature: Databases

Getting Mono and MySQL to play together politely

When I first used Mono, shortly after its first appearance in 2004, one of my most important requirements was to get connected to a MySQL back end. This was quickly achieved at the time with the ByteFX data connector. Following the basic Mono tutorial quickly had me up and running, with access to MySQL databases. Last week I needed to reopen and modernize my application and found that there have been several important changes in Mono between 2004 and 2008. First, I found some "then and now" differences with the installation of the data connector. Second, I needed to make some modifications to my programming.

My test platform for this article was openSUSE 11. I thought that since Mono is run from Novell/SUSE that this might give me the most up-to-date Mono files. To some extent this was correct, as you will see.

Installation issues

The first issue is that the recommended data connector for MySQL is no longer ByteFX. The ByteFX connector will still work for some basic needs, but the Mono project now recommends the MySQL connector direct from MySQL. The DVD install of SuSE 11 includes ByteFX but does not include a MySQL connector, even though there are connectors for other backends such as Firebird and Postgresql.

From the changelog of the ByteFX package it is clear that SUSE is putting work into keeping ByteFX connector up to date. However, according to Miguel de Icaza, ByteFX should only be used in those cases where the MySQL connector will not work.

So I visited the downloads page for the latest and greatest MySQL .Net connector, where I was offered sources for Visual Studio together with precompiled Windows binaries. No mention of Linux binaries. Actually, the Windows binaries worked fine on Linux; I just needed to download the Windows binaries (no installer) package, extract the MySql.Data.dll file, copy it into the /usr/lib/mono/2.0/ (or other directory according to need) and register the dll with the gac:

cd /usr/lib/mono/2.0/
gacutil -i MySql.Data.dll

...and the file became available for adding in the normal manner as a reference in Mono or Monodevelop.

If you follow the excellent little tutorial on connecting your Mono frontend to MySql you will soon run into a small problem: the Mono compiler will not like the references to IDbConnection and IDataReader. Classes are now prefixed with 'MySql' and not 'ID,' as in MySqlConnection and MySqlDataReader.

In addition, let's say you have a connect string for your database in this format (note in particular the single quotes):

This will work if you are using the ByteFX connector, but the MySql connector will fail with a message that the specified host could not be found. Removing the single quotes around 'localhost' will allow the host to be found, but it will not log you in since the user will not be found. The MySql connection string needs to be stripped of single quotes. (In this format it will work with the ByteFX connector, too.)

Password hashing in MySql definitely places some restrictions on which connector can be used. ByteFX will not deal with password hashing in MySql 4.1+, but the MySql connector will.

When setting up your first connection to a back end of any kind, it is helpful to have concrete feedback about why things are not running as expected. Using the try - catch structure will help to demystify the sometimes cryptic, sometimes lengthy information from the compiler:

It's not the Mono developers' fault that specifications have to change and that documents get out of date, but we users need a reference to the changes that need to be made. Luckily, there's plenty of detailed assistance available on the Mono forums.

In the absence of a sophisticated replacement for Access on a Linux machine, having a convenient front end to a MySQL back end in C# -- as provided by Mono -- gives us an alternative. And the more easily and efficiently we can get our first connection going, the more ready we are to attempt the more complex process of actually editing, adding, and deleting data in the database.

Colin Beckingham is a freelance programmer and writer in Eastern Ontario. He is currently working on a project that logs and charts the operation of a biomass burner using open source resources.

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 66.245.126.72]
on August 23, 2008 04:57 AM

Relax people. Nobody's going to force you to run Mono. If you don't like it, move on. I thought Linux was all about choice, after all.
Personally, I rather like developing in .Net and have found Mono to be surprisingly capable.
--Jack

Linux, choice and Mono

Linux IS about choice. But what does that have to do with Mono, which is all about proprietary technology? Especially when the proprietor has repeatedly made threats against Linux and open source.

If you like to program in .net, that's great because it's your choice. But you are NOT writing Linux programs, since the majority of Linux users can't run them (and note that I didn't say 'won't' run them, I said 'can't' run them, although won't is quite true as well (it's that choice again)). And regardless of Miguel's blathering about the license pasted onto Mono, you are not writing open-source programs, since until Microsoft opens .net, Mono is severely tainted.

You can choose open and free, or you can choose the patents of Damocles, but not both. They are fundamentally incompatible.

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 76.14.5.121]
on August 23, 2008 05:24 AM

I believe the animosity towards Mono is well deserved and I worry about Linux.com because of endorsements like these. Don't forgot that the company that makes .NET will stop at nothing to destroy Gnu/Linux/opensource. They have claimed that Linux violates their patents, that Linux is a cancer, and yet they partner up with Novell? I think it's time that EVERYBODY in the open source community opens their eyes and says NO to MONO, MOONLIGHT, and any other tainted code that defies the whole idea of open source.

Getting Mono and MySQL to play together politely

Unless MySQL's instructions say to install the assembly in the GAC, it's not really good practice to do that. You should instead bundle the assembly with your own software.

Of course, if you're not distributing this outside of one server, it doesn't really matter what you do on your machine. ;-)

As for everybody tilting at windmills, this guy took the time to write an article that will be useful to many developers on Linux. You should consider showing him respect by staying on-topic in these comments.

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 68.104.95.17]
on August 24, 2008 01:36 PM

Actually, the real mistake is copying it to /usr/lib/mono/2.0/. Running gacutil will already copy the assembly into the GAC (if that's what you've decided to do)...but placing it in /usr/lib/mono/2.0 makes it look like part of the Mono distribution, which is definitely bad form. In addition, you'll notice that the contents of /usr/lib/mono/2.0 are symlinks to the assemblies that reside in the GAC.

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 59.101.88.7]
on August 25, 2008 01:26 PM

How's your history mate? Can you tell me how many companies have entered into a partnership or agreement with Microsoft and prospered? Do you know how many times Microsoft has been convicted of abusing its monopoly? Do you believe that Microsoft has ever done anything to benefit anyone other than itself? Have you been following the OOXML saga (travesty)? Do you realise that Bill Gates is a thief, a cheat, a liar and a fraud, and that Steve Ballmer is just as bad?

Here's the way it is: mono is just another poison pill from Redmond, and it doesn't matter if you suck it for a day, or a month, or a year - the poison will eventually do its job. Mono has no place in Linux, and articles about it have no place on this web site. Get rid of mono out of Linux, and tell all the shills and trolls to get themselves a copy of Vista - they're welcome to it.

And Sandy, as for 'respect', do you think that Microsoft has ever shown anyone any respect? When they have driven their competitors out of businesses, put people out of work, perhaps destroyed families in the process - was that respect? Microsoft should be excluded utterly and entirely from the open source world; they should be starved of oxygen until they expire.

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 68.192.116.106]
on August 25, 2008 03:08 PM

Actually, Microsoft has open sourced the .Net CLR in the form of a project called Rotor.

Also, Mono != Microsoft and C# is an ECMA language that is not patented, so you might want to check your facts again. The fact is that the only parts of Mono that _might_ have a patent issue are ASP.NET, ADO.NET or Windows.Forms.

Re: Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 69.92.97.210]
on August 29, 2008 01:14 AM

Check your history again, friend. C# may be patent free, but it WAS created by Microsoft initially, and they tied it to .net in an almost irreversible way. Mono is still an IP landmine, despite .net's so called open-ness. How many companies/projects have Microsoft sued for infringmement on their so-called "open" standards? Whenever Microsoft makes a "standard" it is with the express goal of reeling people into their platform.

Mono is still tainted. C# is still... tainted. ECMA is already in Microsoft's poicket, unless you've overlooked the nightmare that was the OOXML standardization.

Getting Mono and MySQL to play together politely

Quote: "Actually, Microsoft has open sourced the .Net CLR in the form of a project called Rotor."

Very interesting - is the code released under the GPL?

I re-iterate my point that Microsoft is a criminal organisation led by criminals. They have been involved in amoral and illegal activity since the very beginning, and that trend is only becoming more pronounced now they are fighting for their survival. Microsoft is a corporate sociopath, and the only way to deal with it is to destroy it. If you don't believe me, go and do some research.

Microsoft have not "open sourced" anything, despite what they may claim - they are pathological liars. They taint everything they touch, and have left a trail of destruction in their wake. Whatever they are saying they have done is either simply for show, or a ploy to suck in the gullible (who seem, sadly, to be quite numerous).

NO Microsoft code should be within cooee of Linux. The phrase "might be a patent issue" when talking of MS code is laughable. To Microsoft, a patent is a loaded gun, just awaiting the right time to be cocked or waved about in a threatening manner. Make no mistake, there is no place for compromise with Microsoft, and certainly no place for Microsoft apologists within the Open Source movement.

Also, the ECMA is in Microsoft's pocket, and has even less credibility than the ISO.

Re: Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 68.192.116.106]
on August 26, 2008 05:47 AM

Your definition of "open source" could use an update. There are many licenses besides the restrictive GPL that are considered open source such as Apache or BSD. If you can get the source code for free, the code is generally considered "open". Really good attempt at proving your point though!

Oh and as for the trail of destruction that you mentioned, have you ever considered how much money the GPL has cost us? Sure, it's great for the users because they can get free software, but did anyone ever think of how much damage it has caused to businesses large and small? Maybe you think that all software should be open source, is that it?

There's nothing more destructive than thinking that the rest of the world should have the same opinion as you.

Your posts are filled with nothing more than name calling, half truths and straw. At this point I can obviously see that you're either a rabid anti-Microsoft troll or you're just trolling for fun. Either way, your opinion is worthless.

Re(1): Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 67.88.6.146]
on August 26, 2008 06:22 PM

you may want to try harder. i can't help but read all the posts here and think that you should follow your own advice.
How in the hell do you conclude that GPL has cost businesses money... I think the MS koolaid is starting to seep into your brain.
you talk of Rotor,thats funnyhttp://research.microsoft.com/programs/europe/rotor/
says there that it is "shared-source implementation"....lol
"WTF is that?
Looks like you may want to rethink your definition of Open source, or just brush up on your research skills cause you've clearly been misinformed.

Re(2): Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 68.192.116.106]
on August 26, 2008 09:06 PM

Actually, there is no official definition of "open source". However, if you weren't so culturally inept you might have noticed that something is generally considered open source if you can get the source code to it.

-1 for more typical troll behavior...you took the name of something (shared source) and twisted it to make it seem like it wasn't open.

Re(3): Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 67.88.6.146]
on August 26, 2008 09:29 PM

I don't know about your definition of OSS, but anyone with common sense can tell you that , it is far from open....lol troll.... sensitive are we....
The Rotor code can be used, modified, and re-distributed, for non-commercial experimentation, as a basis for courseware or lab projects, or as a guide for those developing their own commercial ECMA implementations.
open right....ROFL

Re(4): Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 69.92.97.210]
on August 29, 2008 01:20 AM

The Shared Source licenses are defined by many, ESR and RMS included, as a "fake" open source license. There are actually two shared source licenses. One that is no more open than my car door in a ghetto, thanks to such terms as a NDA clause. The second one is just as crippled as the first, non-commercial distribution.

Both are not taken seriously by open source devlopers and are actually feared as they feel that any engineer or programmer who sees the "open" code is compromised. No company wants to use shared source Microsoft software lest Microsoft come around and sue them for IP infringement.

Don't fool yourselves, people. When Microsoft "opens" something it is clearly with the intent of tainting projects that "benefit" from it. Down with Mono! Get that crap off of Linux!

Getting Mono and MySQL to play together politely

Posted by: Anonymous
[ip: 65.174.156.136]
on August 27, 2008 12:23 AM

I believe Microsoft hires trolls to prowl Linux websites (like this one) and defecate FUD all over the place.

I would rather chew chew glass than program in .NET, install Mono on my Linux machine, or believe for one second that Microsoft code belongs in open source projects. (Real open source projects, not this Rotor bullshit).