ASP.NET MVC

ASP.NET MVC hosting lesson: Elmah and SQL Server 2000

April 3, 2010 · 2 min read

Background

Technically this isn't specific to ASP.NET MVC at all, that just happens to be how I use Elmah. I started work on an ASP.NET MVC project with certain erroneous preconceived notions. I originally started the database with SQL 2008 in mind because I run Windows 7. An easily accessible staging server used SQL 2005 and it was here that I ran into my first compatibility snag. A database project may be set for an earlier revision but you can't transplant those .bak files and expect them to restore. This is generally 101 level stuff but something I tend to keep in the back of my mind at the worst times.

This staging issue foreshadowed production: the shared hosting company I use is running SQL 2000. Argh! Luckily this process was less painful: I used SQL Publishing Wizard and SQL 2000 in a virtual machine to get the database on the lowest common demoninator. Once in SQL 2000, the backup files will easily restore in any future version of SQL. Because the push to production is so infrequent and changes can be diff'd easier than rebuilt I've settled on a structure of Development: 2005, Staging: 2005, and Production: 2000.

Elmah and SQL 2000

I chose an Elmah version (1.1.11517.2009) that dealt specifically with SQL 2005 but was hopefully new enough to be relative to ASP.NET MVC. Switching to SQL 2000 produced a very minor snag: the database script needed to be downgraded.

Fortunately, and with the help of Google code, I could go back to other revisions of the same file in the Elmah codebase and find a version suited for SQL 2000 dated earlier this year. Here's the diff link to show what changes were made: http://code.google.com/p/elmah/source/diff?spec=svn705&r=643&format=side&path=/trunk/src/Elmah/SQLServer.sql&old_path=/trunk/src/Elmah/SQLServer.sql&old=568. When downgrading to SQL 2000, use the left hand side or you could just download the file.

Update (2019): Since Google Code has long been out of service, Elmah can now be found at https://elmah.github.io/. To get an appropriate SQL 2000 file, you may have to look at v1.0 and v1.1 sources. I would think in 2019 you would likely choose a more recent SQL Server version.

While you are there, you might as well follow the examples given by Scott Mitchell Keeping ELMAH's Error Log Size In Check and Deleting All Records In a Table EXCEPT For the N Most Recently Added Records. Why both? The first prunes any records beyond a date range to keep errors relevant. The second makes sure your database stays small in case of anything that can trigger a large number of records within your date window.

Upcoming ASP.NET MVC posts

January 20, 2010 · 1 min read

Most of this may or may not be relevant to your situation but after completing development, staging, and most of the production implementation of an ASP.NET MVC site I wanted to share some of what I learned.

The majority are one or two-off hacks from someone else's code or a down/upgrade where appropriate, creating a Frankenstein. These won't necessarily be in order I don't think.

  • Homepage - various jQuery plugins & content fetching
  • Content/ structure
  • Elmah

    • Code version: 1.1.11517.2009
    • Downgraded ELMAH_LogError stored procedure to SQL 2000
    • ELMAH_LogError pruning taken from 2 blog posts from a single source
  • Editing 1:1, 1:M or M:M in Entity Framework
  • Validation with xVal and DataAnnotations - straight up from the samples
  • Image/Link/CSS/JScriptHelpers - using tagbuilder to eliminate a lot of code in markup
  • jQuery uses

    • Delete links - tweak of an Http Delete implementation
    • Ajaxy Http Post/Gets
    • Image rollover
    • Google analytics
    • TinyMCE
  • Areas

    • Views/Web.config copied from main project
    • T4MVCAdmin fork to handle Links and Controller references (that is now quite old)
  • SQL 2000 from 2005

    • nvarchar(max) to nvarchar(4000) - ntext is more of a 1:1 mapping but it meant significant stored proc changes
    • using SqlPubWiz
  • MsBuild scripts - dependency chaining, SqlPubWiz integration via Community Tasks, etc.

    • Database
    • Web

I'll try to refer to this verbatim as my defacto outline and even that isn't quite structured correctly enough. It'll work itself out as the posts are made I'm sure. I'm using this to hopefully keep me motivated to completing them all.

ASP.NET MVC and CreateArea Extension Method on Restricted Hosting

January 19, 2010 · 1 min read

I've recently switched hosting providers at the company I work for. Instead of being able to use wildcard mapping or the .mvc file extension mapping, I'm left with .aspx.

The premise of this exercise is easily explained here: http://www.asp.net/learn/mvc/tutorial-08-cs.aspx, specifically Listing #3 under the Hosted Server section.

While this is fine for a default MVC1 project, I've currently implemented Phil Haack's Areas v1 prototype with Steve Sanderson's CreateArea extension method located here http://blog.codeville.net/2008/11/05/app-areas-in-aspnet-mvc-take-2/.

To make the Global.asax change from Listing #3 in the first link (phew), you need to modify all routes to add the .aspx extension. The same goes true for .mvc.

I followed Steve's example verbatim and eliminated the default "" (blank) route because isn't necessary in wildcard mapping. What isn't readily apparent is that you absolutely need this when you do get into file extensions.

The fix is a simple but because it felt like the same route/area I didn't think it would work.

routes.CreateArea("Root", "Namespace.Controllers",
    routes.MapRoute(null, string.Empty,
    new { controller = "Home", action = "Index", id = string.Empty })
);

RouteDebug confirmed it gets hit properly so that should be all you need. I haven't tested to see whether you can just add this route and leave it for both file extension and wildcard mapping but it shouldn't be a problem to just add it and leave it.