MySql data-source support for ELMAH
Following on from my last post (a couple of months ago) about Integrating ELMAH with Umbraco, I received a comment if it was possible for ELMAH to use MySQL as a back-end data-source.
After a few emails back and forth between myself and Rajiv, (as well as Rajiv’s requests over at the ELMAH support group), the advice was to simpily develop some code that implemented the ErrorLog class, (making use of the 3 core methods: Log, GetError and GetErrors). Rajiv make a start with this code, but ran into a few problems, (mostly because he was trying to reference methods/properties that were internal to the core Elmah.dll).
Given that I’d said it was quick and easy to develop this code, I best put my money (or time in this case) where my mouth was. Fifteen minutes later the code was written… and then another hour later, the code was tested and bugs fixed.
For the MySQL connectivity, I used the MySql.Data.MySqlClient connector. For the MySqlErrorLog, I followed the code/design patterns that Atif had used in both the core SqlErrorLog and SQLiteErrorLog classes.
I have uploaded the Visual Studio (2008) solution to the ELMAH support group file repo (here is a direct link to the ZIP) – you will need to compile the DLL from the solution. If you need a pre-compiled DLL, then give me a shout, I’ll sort something out.
Once you have the compiled Elmah.MySql.dll, you will need to add following to your Web.config file:
In your <elmah> section, change the <errorLog> to: (if you haven’t installed ELMAH before, please see the WebBase)
<errorLog type="Elmah.MySqlErrorLog, Elmah.MySql" />
In the VS2008 solution, there is a script called MySql.sql – run this against your database to create the new table (called “elmah”) needed to log the errors/exceptions.
Then add your MySql connection string in the <connectionStrings> section:
<add name="ELMAH_MySql" connectionString="SERVER=localhost;DATABASE=elmah;USER=XXXX;PASSWORD=XXXX;" />
It is very important that you call the connection string “ELMAH_MySql” – as this is hard-coded in the backend. (Let me know if this is a problem, I think it could be moved to the <errorLog> section?)
Once you have saved the changes to your Web.config, you are all set to use MySql as your ELMAH back-end data-source!
Known issues:
- The “Sequence” column in the “elmah” table should be auto-incremental, but it isn’t! (I don’t claim to know enough about MySql to have multiple auto-incremental columns) – any suggestions?
- The MySql connection string is hard-coded as “
ELMAH_MySql“ - The code will only compile with .NET 2.0 and above (no support for .NET 1.0 or 1.1 – sorry)
I have mentioned to Atif about the possibility of including MySql support to the ELMAH core – to which he is willing to do, only if I support it. Which I will be happy to do – but only if there is a need for it. So my suggestion would be, if you would like to see MySql support in the ELMAH core – then raise a feature request on the ELMAH Google Code site. Once it gains momentum, we’ll take it from there.



To get the sequence column working you need to use a trigger, like what is done in the Oracle version.
Nick Berardi
November 25, 2009 at 1:43 am
http://elmah.googlegroups.com/web/Elmah.MySql.zip
I get page doesn’t exist. where can i downlaod the mysql provider?
Prabir Shrestha
July 15, 2010 at 3:39 am
Hi Prabir, I have no idea why the download is missing, I just uploaded the ZIP to the ELMAH support forum. I’ve tried a few of the other files on the forum, none of them seem to work either.
There is MySQL support in the “issue-143″ branch, not sure when it will be merged with the trunk, but it might be worth using that branch?
http://code.google.com/p/elmah/source/browse/#svn/branches/issue-143
Cheers,
- Lee
Lee Kelleher
July 15, 2010 at 7:38 am
thanks, actually i ended up writing my own coz, couldn’t wait for it.
tryin to put triggers for sequence as @nick suggested too.
will give out the source code once im done.
Prabir Shrestha
July 15, 2010 at 7:44 am
just finished creating the mysql provider for ELMAH.
you can download it at http://github.com/prabirshrestha/ELMAH.MySql/downloads
pretty much same as yours. but resides in different dll.
thanks a lot
Prabir Shrestha
July 16, 2010 at 4:53 am