Using ELMAH with MySQL

476 views
Skip to first unread message

stumpthegeek

unread,
May 8, 2009, 6:39:29 PM5/8/09
to ELMAH
I'm building a website backed by a MySql 5.0x database and I was
wondering if it would be possible to use ELMAH with it. If so what
steps do I need to take to make ELMAH work with MySql?

Atif Aziz

unread,
May 10, 2009, 7:32:10 PM5/10/09
to el...@googlegroups.com
You need to provide an implementation of the ErrorLog class that knows how to store and retrieve errors from a MySql database. You only need to implement 3 methods of the class, namely Log, GetError and GetErrors.

- Atif

Rajiv Kalra

unread,
Jun 5, 2009, 4:49:10 AM6/5/09
to ELMAH
Hi,

I am facing problem in implementing those 3 methods of class. As I
dont have much idea about how the solution has been created,
specifically how it adds the shortcut of classes to solution. So I am
not able to add my new MySqlErrorLog.cs class to 2008 solution and how
would i compile it to include which dll in my application. So it would
be of great help if you can provide me the mysql implementation or
guide me the way to do it.

Thanks and Regards,
Rajiv Kalra.

On May 11, 4:32 am, Atif Aziz <aziza...@gmail.com> wrote:
> You need to provide an implementation of the ErrorLog class that knows how
> to store and retrieve errors from a MySql database. You only need to
> implement 3 methods of the class, namely Log, GetError and GetErrors.
>
> - Atif
>
> On Sat, May 9, 2009 at 12:39 AM, stumpthegeek <stumptheg...@gmail.com>wrote:
>
>
>
>
>
> > I'm building a website backed by a MySql 5.0x database and I was
> > wondering if it would be possible to use ELMAH with it. If so what
> > steps do I need to take to make ELMAH work with MySql?- Hide quoted text -
>
> - Show quoted text -

Atif Aziz

unread,
Jun 5, 2009, 4:52:18 AM6/5/09
to el...@googlegroups.com
dont have much idea about how the solution has been created,
specifically how it adds the shortcut of classes to solution. So I am
not able to add my new MySqlErrorLog.cs class to 2008 solution and how
would i compile it to include which dll in my application.

Don't bother adding it to the 2008 solution from ELMAH. Write your MySQL implementation in a separate project that references ELMAH.

Rajiv Kalra

unread,
Jun 5, 2009, 6:15:25 AM6/5/09
to ELMAH
Hi,

Could you please provide me the mysql implementation for Elmah?

Regards,
Rajiv Kalra

On Jun 5, 1:52 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > dont have much idea about how the solution has been created,
> > specifically how it adds the shortcut of classes to solution. So I am
> > not able to add my new MySqlErrorLog.cs class to 2008 solution and how
> > would i compile it to include which dll in my application.
>
> Don't bother adding it to the 2008 solution from ELMAH. Write your MySQL
> implementation in a separate project that references ELMAH.
>
> On Fri, Jun 5, 2009 at 10:49 AM, Rajiv Kalra <rajivkalra1...@gmail.com>wrote:
>
>
>
>
>
> > Hi,
>
> > I am facing problem in implementing those 3 methods of class. As I
> > dont have much idea about how the solution has been created,
> > specifically how it adds the shortcut of classes to solution. So I am
> > not able to add my new MySqlErrorLog.cs class to 2008 solution and how
> > would i compile it to include which dll in my application. So it would
> > be of great help if you can provide me the mysql implementation or
> > guide me the way to do it.
>
> > Thanks and Regards,
> > Rajiv Kalra.
>
> > On May 11, 4:32 am, Atif Aziz <aziza...@gmail.com> wrote:
> > > You need to provide an implementation of the ErrorLog class that knows
> > how
> > > to store and retrieve errors from a MySql database. You only need to
> > > implement 3 methods of the class, namely Log, GetError and GetErrors.
>
> > > - Atif
>
> > > On Sat, May 9, 2009 at 12:39 AM, stumpthegeek <stumptheg...@gmail.com
> > >wrote:
>
> > > > I'm building a website backed by a MySql 5.0x database and I was
> > > > wondering if it would be possible to use ELMAH with it. If so what
> > > > steps do I need to take to make ELMAH work with MySql?- Hide quoted
> > text -
>
> > > - Show quoted text -- Hide quoted text -

Atif Aziz

unread,
Jun 5, 2009, 6:20:36 AM6/5/09
to el...@googlegroups.com
Could you please provide me the mysql implementation for Elmah?

Sorry, I don't know MySQL. Never used it so I am not in the best position to implement one.

Rajiv Kalra

unread,
Jun 5, 2009, 8:51:25 AM6/5/09
to ELMAH
Hi,
ok i know mysql, so please guide me to resolve the problems i am
getting so that we can together accomplish this task.
I have included mysqlerrorlog in my own project after changing it from
sqlserver to mysql and facing the following issue.

CS0122: 'Elmah.ConnectionStringHelper' is inaccessible due to its
protection level

On Jun 5, 3:20 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > Could you please provide me the mysql implementation for Elmah?
>
> Sorry, I don't know MySQL. Never used it so I am not in the best position to
> implement one.
>

Atif Aziz

unread,
Jun 5, 2009, 8:57:05 AM6/5/09
to el...@googlegroups.com
so please guide me to resolve the problems i am
getting so that we can together accomplish this task.

Sure, let's try. :)


CS0122: 'Elmah.ConnectionStringHelper' is inaccessible due to its
protection level

Unless you plan on supporting .NET 1.x, you don't really need ConnectionStringHelper to resolve connection strings. Just use the standard .NET 2.0 way of reading connection strings from configuration and remove code using ConnectionStringHelper.

Rajiv Kalra

unread,
Jun 5, 2009, 9:15:57 AM6/5/09
to ELMAH
ok i will try this way and respond back to you .

On Jun 5, 5:57 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > so please guide me to resolve the problems i am
> > getting so that we can together accomplish this task.
>
> Sure, let's try. :)
>
> CS0122: 'Elmah.ConnectionStringHelper' is inaccessible due to its
>
> > protection level
>
> Unless you plan on supporting .NET 1.x, you don't really need
> ConnectionStringHelper to resolve connection strings. Just use the standard
> .NET 2.0 way of reading connection strings from configuration and remove
> code using ConnectionStringHelper.
>

Rajiv Kalra

unread,
Jun 8, 2009, 3:03:12 AM6/8/09
to ELMAH
Hi Atif,

I tried the way told by you. Following are some more issues i am
facing.

-->Error 4 'Elmah.Mask' is inaccessible due to its protection level D:
\myappname\App_Code\MySQLErrorLog.cs 63 30
mysolution: what i have tried is accessed the application name same
way as connection string.


-->Error 5 'MySql.Data.MySqlClient.MySqlCommand' does not contain a
definition for 'ExecuteXmlReader' and no extension method
'ExecuteXmlReader' accepting a first argument of type
'MySql.Data.MySqlClient.MySqlCommand' could be found (are you missing
a using directive or an assembly reference?) D:\myappname\App_Code
\MySQLErrorLog.cs 159 44

comment: I think you wont be able to tell me about this as this is
related to mysql

-->Error 6 'Elmah.Debug' is inaccessible due to its protection level D:
\myappname\App_Code\MySQLErrorLog.cs 283 13

Atif Aziz

unread,
Jun 8, 2009, 3:54:47 AM6/8/09
to el...@googlegroups.com
> 'Elmah.Mask' is inaccessible due to its protection level

You can just add this to your project verbatim. It's a very small helper class. Its Mask.NullString method is not even needed if you're working with C# 2 or later since it can be replaced by the null-coalescing operator (??).

> 'Elmah.Debug' is inaccessible due to its protection level

Again, either include it verbatim in your project or just replace with calls to System.Diagnostics.Debug

>>
'MySql.Data.MySqlClient.MySqlCommand' does not contain a
definition for 'ExecuteXmlReader'
<<

I think you start with SqlErrorLog as your base code. ExecuteXmlReader uses the native XML capabilities of SQL 2000+. You may need to adjust this for MySQL if it doesn't offer similar features. You may want to look at how SQLiteErrorLog saves as loads the XML.

- Atif

Rajiv Kalra

unread,
Jun 8, 2009, 6:37:01 AM6/8/09
to ELMAH
Hi,

these problems have been solved as guided by you..but now the issue is
how should i specify my MySQLErrorLog.cs class in web.config. As i am
doing the same way as it is done with sqllite

<!--<errorLog type="Elmah.SQLiteErrorLog, Elmah"
connectionStringName="ELMAH.SQLite"/>-->
<errorLog type="Elmah.MySQLErrorLog, Elmah"
connectionStringName="ELMAH.MySQL" />
and
<!--<add name="ELMAH.SQLite" connectionString="Data Source=|
DataDirectory|errors.s3db"/>-->
<add name="ELMAH.MySQL" connectionString="Database=dbname; Data
Source=dbip; User Id=root; Password=pwd;"/>

but its not working. what can be the problem?

James_2JS

unread,
Jun 8, 2009, 6:44:43 AM6/8/09
to ELMAH
Hi there!

Your problem is that you are trying to find MySQLErrorLog within
Elmah.dll... when in fact it resides in your own dll...
So you should be doing something like this...

<errorLog type="YourNamespace.MySQLErrorLog, YourDll"
connectionStringName="ELMAH.MySQL" />


Cheers,

James

On Jun 8, 11:37 am, Rajiv Kalra <rajivkalra1...@gmail.com> wrote:
> Hi,
>

Lee Kelleher

unread,
Jun 8, 2009, 7:13:39 AM6/8/09
to ELMAH
(Rajiv contacted me off-list, via my blog post about Elmah/Umbraco
integration: http://blog.leekelleher.com/2009/04/23/integrating-elmah-with-umbraco/
)

I have written a MySqlErrorLog class (in a standalone project) that
references the Elmah.dll, extending the ErrorLog class.

The VS solution files are available to download here:
http://groups.google.com/group/elmah/web/Elmah.MySql.zip

You just need to compile them. I created the VS solution in VS2008 -
so let me know if you have any problems opening the solution.

For the record, I am in no way an expert in MySql, I know enough to do
what I need - so if there are any improvements to be made, please feel
free to contribute!

Thanks,
- Lee Kelleher

Atif Aziz

unread,
Jun 8, 2009, 8:17:56 AM6/8/09
to el...@googlegroups.com
problem is that you are trying to find MySQLErrorLog within
Elmah.dll... when in fact it resides in your own dll...

James is right on. I noticed earlier, however, when you mentioned the compiler errors, that you may have your log implementation code sitting in the special App_Code directory so I wanted to point out that you can just use "App_Code" as the assembly name (the actual one is unknown due to dynamic compilation). In other words:

<errorLog
  type="MySQLErrorLog, App_Code"
  connectionStringName="ELMAH.MySQL" />

If your type lives in a namespace, then prepend it to MySQLErrorLog.

- Atif

Rajiv Kalra

unread,
Jun 8, 2009, 9:32:23 AM6/8/09
to ELMAH
Hi All,

Thanks a lot to all of you guys Atif, James and specially to Lee who
has provided me the working solution. It was great experience working
with you guys.

On Jun 8, 5:17 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > problem is that you are trying to find MySQLErrorLog within
> > Elmah.dll... when in fact it resides in your own dll...
>
> James is right on. I noticed earlier, however, when you mentioned the
> compiler errors, that you may have your log implementation code sitting in
> the special App_Code directory so I wanted to point out that you can just
> use "App_Code" as the assembly name (the actual one is unknown due to
> dynamic compilation). In other words:
>
> <errorLog
>   type="MySQLErrorLog, App_Code"
>   connectionStringName="ELMAH.MySQL" />
>
> If your type lives in a namespace, then prepend it to MySQLErrorLog.
>
> - Atif
>
Reply all
Reply to author
Forward
0 new messages