Debug ASP.Net Applications Using ELMAH: Part 2

Background

My previous article is Debug ASP.Net Applications Using ELMAH: Part 1. Now in this article I will be explaining the integration of ELMAH with SQL Server (SSMS). This is currently an essential part in any application. That is, when errors and exceptions arise in the application they are logged into the database tables that are related to ELMAH. These table scripts are provided by ELMAH itself. Don't believe it? I also did not. But that is the truth. Let's see and discuss now.

ELMAH Configuration

Here I am specifying all the requirements for setting up ELMAH in the web.config settings. Since the installation and also the settings have been explained in Part-1, still I am specifying the blocks required in the Web.Config. Inside the System.webServer block:

  1. <modules runAllManagedModulesForAllRequests="true">  
  2.    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />  
  3.    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />  
  4. </modules>Snippet  
  1. <handlers>  
  2.    <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />  
  3. </handlers>  
The preceding are the modules and handlers as well. Inside system.Web:  
  1. <httpModules>  
  2.      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />  
  3.      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />  
  4.    </httpModules>  
  5.    <httpHandlers>  
  6.      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />  
  7. </httpHandlers>  
The preceding are the common settings for the ELMAH. Now let's look into the settings required for database settings.

Since we all have an access and look at the connection strings. Still let's have a quick look:
  1. <connectionStrings>  
  2.    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-DemoStart-20141014045047.mdf;Initial Catalog=aspnet-DemoStart-20141014045047;Integrated Security=True" providerName="System.Data.SqlClient" />  
  3. </connectionStrings>  
The preceding is the pattern of the connection strings. Don't use the same ones. Just kidding. ;) Then the final change for the ELMAH with the SQL is as in the following:
  1. <elmah>  
  2.    <security allowRemoteAccess="yes" />  
  3.    <errorMail from="[email protected]" to="[email protected]" subject="DEMO Error" async="false" useSsl="true" />  
  4.    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="DefaultConnection" applicationName="DemoStart"/>  
  5. </elmah>  
This was the final change required for the web.config change to integrate ELMAH with SSMS.

Queries for ELMAH

Now, let me reveal the magic to you as I said earlier. Yes guys, we don't need to write queries. Ready-made queries are provided by the ELMAH team. The download link for the ELMAH Queries is :Queries for ELMAH.

Queries for ELMAH

Just simply download the ".sql" file and run in the SSMS. After execution the tables are created for the ELMAH as well as the Stored Procedures shown below:

ELMAH error

As you can see above, the tables and Stored Procedures are added into the database. This is so simple and as simple it can be. Isn't this great?

Let's see the number of columns and what columns are being created in the table.

number of columns

dbo.ELMAH_Error

Then every exception that occurs will be added into the table and can be easily used by developers for future reference.

I hope this helps developers anyway. This article covers all the setting configurations required. Thus the setup is as simple as it can be. Thanks to Andy Frenchh


Similar Articles
Invincix Solutions Private limited
Every INVINCIAN will keep their feet grounded, to ensure, your head is in the cloud