Friday, 30 October 2009

MySQL Connector - Error with Multiple Versions on Dev Machine - "...column 'InvariantName' is constrained to be unique..."

I installed another version of the MySQL connector on my development machine yesterday, parallel to my existing version - so I now have both 5.0.6 and 5.07 installed. I use these two different versions of it for a couple of different applications I work with. Now however I find that I’m unable to open EDMX files in projects using Entity Framework. I get the following error when I double click on the designer file:

Looking at the machine.config file, I can see there are 2 entries in there for MySQL and sure enough, the invariant names are the same:

<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

The solution - basically instead of uninstalling one of the MySQL Connectors, I just commented one of them out in the machine.config file. Now my EDMX designer works again ;-)

Thursday, 29 October 2009

The potential PROs and CONs of using ASP.NET MVC 1.0 for your next web project...


  • Properly testable and allows you to develop more elegant code.
  • You are ‘forced’ to apply the MVC design pattern by the framework, so the only option is to have a properly defined data model + business logic layer (Model), presentation layer (View) and controller to manage their interaction.
  • You also don’t have to deal with the ASPX page lifecycle.
  • Because ASP.NET MVC is RESTful also, it can be used easily with jQuery/JSON, etc - the way the application is organised is more like a RESTful service. The ‘Views’ are like enhanced transforms, layered across the top of the service, that convert the dynamic application output into HTML (if that’s how you choose to define your View), rather than a series of concrete ‘pages’.
  • Because of the way the URLs are put together (i.e. you mostly don’t need to use a suffix - like .aspx - especially under IIS7), the style is better aligned for web search engine optimisation.
  • Web design is much easier - if you get a nice HTML page from a designer, it’s much easier to integrate with the application.
  • You don’t end up with crazy HTML element names, view state in the page, etc - there appears to be much less ‘behind-the-scenes’ messing around with the output HTML by the ASP.NET process than there is with WebForms.


  • It’s a different way of thinking than WebForms, from a Microsoft web-dev perspective - almost completely. So there’s a learning curve. When you get used to it however, it does seem more ‘natural’ approach than WebForms.
  • It’s new, so although MVC version 1.0 is integrated into .NET 3.5 SP1 (although I understand MVC 2.0 is now available - with VS2010 Beta...?); you need to know a few special tricks to get things up and running in production. You need to download some ‘futures’ resources from CodePlex, etc.
  • There are not that many people out there using it yet, so there’s less support and material out there, if you need help.

SQL Server - database mail - just “because you can”, doesn’t make it right!!

Was thinking the other day (discussing across the office with a couple of colleagues actually ;-) about using database mail out of SQL Server in relation to using .NET components to send mail – kind of a hot topic for us, or at least one that's heating up.


My opinion on this type of thing (thankfully shared by our DBA) is that despite the fact that SQL Server provides a very adequate email platform, and there are lots of MSDN type examples out there showing you how do this type of thing, sending bulk email from the database server (for – e.g. – an email marketing campaign type stuff) is bad form.


For one thing you're putting unnecessary load on the server and slowing down applications that are using the server for doing what it's designed to do (manage and serve up relational data), and for another thing – there is simply much better support for doing this type of thing outside of the database, in application code.


Here's my analogy; say you want to do some work on your car – among other tools, you have an adjustable spanner and a professional socket set. Using database mail for everything is like using the adjustable spanner for everything "because you can". You save overhead by not having to change tools here and there, but you spend much more time overall trying to get to places in the car that a professional socket set could reach with ease. And your mate who you asked to help you ends up standing around because he wants to use the spanner too…


The moral of the story - just "because you can", doesn't make it right!!



Sunday, 18 October 2009

Using ASP.NET MVC 1.0 with Dynamic Data...

Getting Started:

Dynamic data is part of 3.5 SP1, but if you want to use MVC you need to specify that the DLLs should be copied to your \bin folder:

Setting “Copy Local” to True for the highlighted DLLs will copy them to the output folder automatically when you build and publish. Makes a bin-deploy of the MVC project easier.

...And Then:

Then, go to this site:

...and get this sample:

You need to reference system.web.dynamicdata:

Here's what needs to be done to enable configuration of DD for a new site:

Need to use entities data source DD project if using entities:

Need to reference the System.Web.Entity assembly:

...or you get this error message: “The type or namespace name 'EntityDataSource' does not exist in the namespace 'System.Web.UI.WebControls'”

Copy the following code into your Global.asax.cs file in order to get your Dynamic Data working in the original MVC project, with your existing entities:

MetaModel model = new MetaModel();
model.RegisterContext(typeof(), new ContextConfiguration() { ScaffoldAllTables = true });
routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = model

Authentication – good article:

Dynamic Data – displaying database errors:

Entities Framework: If/When you get this error - “Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.”:

Need Dynamic Data Futures DLL

Handling DD custom views:

Other Tips:

File upload field template:

If you put html tags into any of the fields you want to edit in your dynamic data views, you will cause it to stop working.

Good link for DD date formatting:

Saturday, 17 October 2009

Web.Config Inheritence to Virtual Directory Application - 'inheritInChildApplications' Attribute...

Had a problem recently where an ASP.NET MVC 1.0 site was not reading the web.config in the virtual directory that we has created for it (using Helm). It was defaulting back to the main site's web.config file (in the wwwroot directorty). The error message we got was like this:


Server Error in '/blah' Application.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly 'MagicAjax' or one of its dependencies. The system cannot find the file specified. (<path_to_folder>\wwwroot\web.config line 133)

============================================================, (FYI, this has nothing to do with MagicAjax, just using this error as an example of the type of problem that can crop up) the site is trying to read '<path_to_folder>\wwwroot\web.config', instead of the web.config file in the virtual directory we had setup, which was  '<path_to_folder>\wwwroot\blah\web.config'. 

This problem is something that can be handled in the top level (wwwroot) config file by using the 'inheritInChildApplications' attribute – the following article provides further detail:

I encountered this error on the evening of deployment – a couple of long hours of tense Googling yielded this result, which worked...

Migrating (and Open-Sourcing) an Historical Codebase: SVN-to-Git

I have a SVN repo on my local machine that I have been shoving stuff into since before I knew how to use revision control systems properly (...