Skip to main content

Get mySQL running with MonoDevelop

Disclaimer:

for anybody trying to look into Mono, you might also want to be able to use a database with easy ADO.NET access like you are used to in MS C#. especially if you think about getting an ASP.NET site running in Linux, you will have a database you need to use. 

MS provides nice dlls for Ado.NET for Oracle and MS SQL. 

so if you want to use linux you will now also probably want some free DB that you can use.

mySQL is the way to go. Unfortunately this does not work out of the box. I spent some hours until i had accomplished getting mySQL to work with Mono with ado.NET. 

this is something i did back a while, and already posted my experience in ubuntuforums.org but... well, to fill this place with some new acticle i will repost it here:

I am trying to get the mySQL ADO.Net provider Connector/Net 5.1 to run under mono. as far as mySQL says so, it should run under mono. 

For this i followed the steps at 
http://mysql.mirrors.pair.com/doc/re...tion-unix.html.

So I followed the provided steps but: 
When i add a reference to the dll i can compile the program without problems. 
But then the errors begin. 

if you want to solve this follow these steps:

you will have to compile the sources for yourself, which sounds strange to any developer being used to .NET. but this is something that one has to do sooner or later when working with linux  :)
and do not worry: here is a step by step guide:

downloaded the source code from
http://dev.mysql.com/downloads/connector/net/5.1.html


extract the archive and you will get a solution.you wont be able to open the solution in monodevelop. one of the projects is missing so monodevelop will abort (in the current version i have). 
i solved this by opening the solution in visual studio. VS complains, but opens it up anyway. delete the non-existing project. now delete every project that has ".CF" and "Test" in it. They do not compile under monodevelop (at least not out of the box) and you dont need them anyways. 
what should be left are the projects mySQL.Data and mySQL.Web. Those should be able to compile with a small tweaking:

Open up the AssemblyInfo.cs files in both projects and comment out the last line:
//[assembly: AssemblyKeyName("ConnectorNet")]

*Now open up the project under monodevelop. 
*build it. 
*no errors. 
*hooraaay 

i can use this own-built DLL without any problems in my projects. and you should be able to do so too!

congratulations! you are now able to work with  ADO.NET/mySQL under Mono!

hope this helps some .NET freaks out there to save some hours and also helps spread out Mono and mySQL as well!

happy coding

Comments