11

I am using MVC 3 with SQL Server 2008 R2 DB.

I installed elmah 1.2.2 and SQL Server script.

Might anybody have some detailed information on how to setup Elmah with SQL Server 2008.

I checked online but could not find detailed information.

Nate Pet
  • 44,246
  • 124
  • 269
  • 414

1 Answers1

16

Since you have already run the SQL Server setup script and installed Elmah in your MVC application, you should just need to add the following to your web.config to have Elmah send its logs to your sql server instance.

<elmah>

 ...

   <errorLog type="Elmah.SqlErrorLog, Elmah" 
      connectionStringName="<definedConnectionString>" 
      applicationName="MyAppName"/>

 ...

</elmah>

Keeping in mind that you will need to replace "<definedConnectionString>" with the name of the connection string that points to your SQl 2008 instance from your <connectionStrings> section of your web.config.

I would also recommend reading through the following 5 part series: Logging Errors with ELMAH and MVC 3, it contains a lot of great recommendations for using ELMAH with MVC. Also you might consider using installing the Elmah.MVC NuGet Package to change the default behavior of Elmah within an MVC application.

Paige Cook
  • 22,415
  • 3
  • 57
  • 68
  • Thank you. Can I follow the same instructions from the 5 part series for Elmah.MVC or are there any different instructions for this? – Nate Pet Sep 19 '12 at 16:09
  • Elmah.MVC will handle the first 3 parts for you automatically. But reading through those parts will help to have a better understanding of what is going on. – Paige Cook Sep 19 '12 at 16:58