Using SQL Spatial on AppHarbor

by Richard 2. May 2012 17:34

I'm now using AppHarbor for all my websites including Aussie Bushwalking and I'm loving it. My new site (hopefully released very soon) required some SQL Server Spatial operations in the code. No problems, hit up NuGet to grab the Microsoft.SqlServer.Types assembly and we're away. But unfortunately an unmanaged DLL, SqlServerSpatial.dll, is also required so you'll need to do a little more playing before it works.

You'll need to copy the SqlServerSpatial.dll into the bin folder of your app, then make sure to add it to:

  • Your project - set the Build Action to Content
  • Your source control (normally mine is set to exclude the bin folder by default)

You can find SqlServerSpatial in two locations:

  • %SystemRoot%\System32
  • %SystemRoot%\SysWOW64

AppHarbor requires the 64-bit version so grab it from SysWOW64. Once that's done, deploy and enjoy all the goodness that the spatial types give you :)

LINQ Distinct without IEqualityComparer

by Richard Mason 17. August 2009 17:11

One annoying issue with the LINQ Distinct function is that it requires an IEqualityComparer. Often I'd (and many others based on the info out there) would prefer to just provide a lamdba indicating which field to compare on, or simply a predicate for doing the compare.

There's at least one solution out there which uses a generic implementation of IEqualityComparer which works fine and another which simply implements the Distinct iteratively. Instead I figured you could instead build it up using Reduce... woops I mean Aggregate.

static IEnumerable<T> Distinct<T>(this IEnumerable<T> list, Func<T, T, bool> comparer)
  return list.Aggregate((IEnumerable<T>)new T[0],
    (a, b) => a.Any(c => comparer(c, b)) ? a : a.Concat(new[] {b}),
    a => a);
static IEnumerable<T> Distinct<T>(IEnumerable<T> list, Func<T, object> selector)
	return Distinct(list, (a, b) => selector(a).Equals(selector(b)));


Two versions, one for just specifying that the compare should happen on some calculated value and another for providing a custom compare function. 

Now this might not be the most efficient method of implementing this, but it's kind of nice, but I'm a bit unhappy with the fact that this is no longer a lazy list. I have a solution for that as well, but it's nowhere near as clean as this :(

Quiet Time Delivers AussieBushwalking

by Richard Mason 26. May 2009 15:49

It's been a bit quiet on the RikWare blog in the last... umm... well quite a while! But whilst my blog has been quiet there's been plenty of work going on behind the scenes.

I've finally released my latest project - Aussie Bushwalking - is now in the public arena. Aussie Bushwalking is basically a collaborative site for sharing bushwalking information. It really comes about from my love of bushwalking and the lack of ideas for walks in my area :) Hopefully Aussie Bushwalking will help me, and others, find new ideas for bushwalks.

I've still got a pile more ideas to add, but if you've got any ideas then please send them through. And don't worry, whilst the site is focused on Australia/New Zealand, there's already one European walk out there and I'm keen to get other overseas walks listed.

RikMigrations 0.2 Released

by Richard Mason 13. May 2008 13:08

There's a new release of RikMigrations available. This includes a lot of bug fixes from the original release and is the first since the development team expanded.

Big thanks to Andy Stewart in particular who has pushed the release out the door and is actively working on more improvements, particularly cleaning up my original messy code.

This also marks the official move of the codebase from CodePlex to Google Code. This change is mainly to get around problems with CodePlex's source control.

kick it on

TimeSpanPicker released under BSD

by Richard Mason 30. April 2008 17:49

A request via email has encouraged me to release the TimeSpanPicker control I blogged about a few years ago. The details are available at but I've copied them in here for ease of reading: 

The TimeSpanPicker is a Windows Forms UpDown control for editing TimeSpan values. It is currently used in RikPVR (

The control is provided, as is, under a BSD license (meaning it's free to use and alter in free or commercial projects). Any improvements will be greatly appreciated.

A Visual Studio 2008 solution (including binaries) containing the project is available here: (11.43 kb)

The project targets .NET 2.0 and should be simple to recompile in Visual Studio 2005.

The control supports input via keyboard, mouse wheel or via the up/down buttons. It is also theme aware.

kick it on

RikMigrations - There was movement at the station

by Richard Mason 28. March 2008 06:17

RikMigrations has started rolling again recently. It appears some posts on the mailing list prompted a few people to check it out and even better some have signed on to contribute as well. This prompted me to commit the changes I've made in the last few months (I'd been meaning to do it but had been lazy).

There's already the start of an msbuild task for RikMigrations and rumblings of a NANT one as well. Plus, a nice little tweak to use generics to define column types so you can do this:


And there's also discussion starting around adding some ability to populate the database with initial values in migrations as well (

PS. For the non-Australians out there the title refers to a famous Australian poem.

kick it on

RikMigrations - Starting from an existing database

by Richard Mason 20. December 2007 06:44

RikMigrations includes support for generating an initial migration from an existing database. Currently this only supports SQL Server databases. The feature was included in the initial release, but hadn't had much testing. Since then I've tested it on a database at work and confirmed it's working correctly (at least to some extent). The migration generator attempts to ensure tables are created in the correct order, but this feature was hacked in and needs improving. In doesn't support circular dependencies so don't even try.

The generator only supports generating in C# at the moment, however it uses CodeDom so other support for other languages is simple to add and a quick hack of the code will provide a version for your favourite language. 

To generate a migration from a database use the following command line:

RikMigrations auto -s:(local) -db:Test -f:Migration.cs 

You can also add the "-sf" flag to write each table into a separate class, but make sure you include a "{0}" in the filename to indicate where to place the name of the table.

kick it on

SQLite for RikMigrations

by Richard Mason 27. November 2007 05:55

I've just added support for SQLite to RikMigrations. This was done mainly because I use SQLite to store data in RikPVR and I needed to expand the schema. I tossed up whether to go with the embedded sql scripts like I have been doing or put in the time to add support to RikMigrations so I could use it. Eventually I decided it would be worth the work of adding to RikMigrations, if only to test how well it would support alternate database providers.

As expected, I had to refactor the code to support the change - alternate database providers wasn't in the original RikMigrations design, though I had already started refactoring towards a provider pattern. However, the changes were actually fairly minimal. I encourage others to sign up and start adding support for other engines.

Unfortunately, SQLite is a bit limited in some areas so not all features are supported. The biggest one is probably the inability to drop columns. There are workarounds for this in SQLite which I may look in to, but for the moment it will just throw an exception. Other ones I've run into is that you don't seem to be able to add columns with PRIMARY KEY or UNIQUE constraints on them once the table is created, but they work fine if they're added during the initial table construction.

In other news I've added a couple of extra pages to the RikMigrations doco. I'll keep adding to that bit by bit but if you have any specific questions drop me a comment or an email.

Finally, here's a quick bit of code in the meantime to show how to use SQLite instead of SQL Server. (This is only for programmatic access, I haven't added the command line interface yet)

DbProvider.DefaultConnectionString = @"Data Source=D:/TestDB.db";
MigrationManager.UpgradeMax(typeof(Joe1).Assembly, typeof(SqliteProvider));

The actual migrations stay exactly the same, except you may run into the limitations I mentioned earlier. I'll try to document them somewhere.

kick it on


Announcing RikMigrations

by Richard Mason 22. November 2007 04:45

Over the last couple of weeks I've been working on a migrations framework for .NET called RikMigrations. There's a couple of existing frameworks but they're mostly integrated in other large projects like SubSonic or didn't quite fit my needs/wants.

RikMigrations is currently relatively small and simple, but I am releasing it under a BSD license on CodePlex so others can jump on board and build it up. Check out the project homepage at to find out more, including a simple tutorial demonstrating its use. 

kick it on

Redirect domain names using UrlRewrite.NET

by admin 30. October 2007 11:43

UrlRewriter.NET is a great tool for url rewriting in .NET. It can even be used to redirect domain names with.

e.g. RikPVR's main address is, but it can also be found at, or but ideally these should just redirect to the primary address. Using a host condition in UrlRewriter.NET makes this easy:

<if header="HOST" match="^((|(|($">
<redirect name="RikDVR" url="^(.*)$" to="$1" />

About Us

RikWare is a software development company based in Brisbane, Australia. Led by director, Richard Mason, RikWare focusses on solving challenging business problems promptly and effectively.

RikWare is also the owner of Aussie Bushwalking, a free, wiki-like collaboration site for bushwalkers and the creator of RikMigrations, a migration framework for .NET.

Aussie Bushwalking

Want to discover some new bushwalking ideas? Share a few of your own? Aussie Bushwalking is like Wikipedia... but for bushwalkers. Head on over. Anybody can see the walks and it's free to sign up and share your own.



RikMigrations is a database migration library for .NET based on the migrations facility provided by Ruby on Rails. It allows simple upgrading and downgrading of databases using .NET code (such as VB or C#) either from the command line or built into your application. Unlike many other migration frameworks, RikMigrations is a stand-alone library which does not rely on a large surrounding framework.