Archive for the ‘Uncategorized’ Category

Why I’m not posting how to get .NET 4.0 working in Windows 2000

Tuesday, August 3rd, 2010

The most popular part of my blog is the posts that I have made on how to get .NET 3.5 (partially) working in Windows 2000, so why am I not continuing this with .NET 4.0?

The truth is that I originally did the .NET 3.5 approach for a specific project where a client of mine had a large number of Windows 2000 PCs. I wanted to be able to use .NET 3.5, and I didn’t want him to be saddled with the upgrade costs. However, since then, he has been gradually replacing those PCs with Windows XP and now Windows 7 PCs, until he only had 2 or 3 Windows 2000 machines left. I recommended to him that it was better for him to upgrade/replace the last ones rather than me trying to get .NET 4.0 working on the old ones, which probably wouldn’t be as cost efficient.

I realise that this might be a disappointment to some people who have still got lots of Windows 2000 machines out there. If anyone does come up with a way of doing it (possibly based on my .NET 3.5 approach), please let me know and I’ll post it up, crediting you.

Unhandled exception clr20r3 mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

Tuesday, August 3rd, 2010

A few weeks ago, I hit a problem that an application that I wrote suddenly started randomly dropping out with an unhandled exception. I can’t remember all the specifics anymore, but I do remember that the event that was written to the logs (that can be viewed in Event Viewer in Administrative Tools in Control Panel): -

EventType : clr20r3
P9 : mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

The most confusing thing about this was that I have a system built in to the application to catch unhandled exceptions, and this had been working fine in the past for a few years. I couldn’t understand why it wasn’t catching this exception.

What was even more confusing was that it was randomly affecting several machines in different sets of circumstances. I eventually managed to find something that would reliably reproduce the problem, but when I tried it on my development PC in the debugger, it worked fine (I still haven’t worked out why this is).

I initially thought that maybe it was because I had just upgraded to Visual Studio 2010 and tried to back-convert my application back to Visual Studio 2008, but the problem continued. I also tried using remote debugging to track down the problem, which also caused a lot of problems as the application still seemed to be dropping out even with the remote debugger running!

I eventually tracked down the problem using a Try, Catch clause around code which I knew would reproduce the problem. The exception was about a missing resource file. I hunted around and eventually found that the resx file for the error handling dialogue window seemed to have been excluded from the project, presumably due to some bug while it was being upgrade to Visual Studio 2010.

After I put the resx file back, I was able to see that the application was throwing an exception. My code for dealing with the unhandled exception had caught it and been throwing the other exception, which didn’t have anything to catch it, so the Common Language Runtime (or Windows?) killed it.

Edit: The actual exception type that was being thrown was System.Resources.MissingManifestResourceException

Why I think that Graphic/Web Designers shouldn’t write HTML/CSS

Thursday, July 29th, 2010

Over the years, I’ve worked on a number of different projects, and I’ve come to the conclusion that for a reasonable size site, graphic design should be done as an image and the translation of that into HTML/CSS should be done by programmers.

This inevitably causes confusion and consternation from web designers and clients as they feel that the web designers should be writing the HTML.  I’ve put together this post to explain why I have found that to be a bad idea.

In my opinion, designers don’t tend to know how to write good, standards compliant HTML and there is no reason that they should need to.
OK, so I’m generalising a bit here, but I’ve never come across a web designer who makes neat HTML and CSS, doesn’t use table layout and validates according to standards compliance checking systems.

The thing is that designers are focused on making things look pretty. That is the way that it should be, and worrying about how they are going to implement something in HTML can interfere in that process. A good metaphor is that you don’t expect an architect to actually know how to build a house – you go to them to design a building that looks good. The builders actually translate those plans into a real life building. If the architect had to worry about where every brick was going to go, what was the best mix of mortar for this region and whether it was compliant with all the building regulations, it could really get in the way of their creative process.

Of course, there is a problem with that analogy, which is that architects do need to worry about some of the practical side of things. They can’t design a house with the front door a metre off the ground with no steps because it would make the house very difficult to access. In the same way, a good designer should either be well versed in usability or work with someone who is (frankly, they probably should be anyway, because they should be designing things to focus people’s attention on the important areas of a page). They should also work with the programmer to ensure that their design covers everything that is needed to meet any technical requirements. Otherwise you can end up with eg. not enough space for the required menu items.

Note that I haven’t said that the designer needs to check with the programmer that the design is possible to implement. The reason I haven’t is that I’ve never hit this problem and I doubt that it arises very often. HTML/CSS is pretty powerful and if you know what you are doing, you should be able to implement just about any design (of course, it might not be easy).

Designers generally don’t (need to) worry about standards compliance. You might wonder why standards compliance is important, and that is a whole other discussion, but in brief, it makes it much easier and cheaper to maintain the site in the long term, improves browser compatibility, SEO and accessibility.

Designers generally don’t think about cross browser compatibility. There are at least 4 main web browser engines these days (Trident/Internet Explorer, Gecko/Firefox, Webkit/Chrome/Safari, Opera) several versions of each and a number of less common ones. There are increasingly more and more new engines popping up for things like mobile devices (although a lot use adapted versions of the main engines too).

Another area that designers are understandably inconsiderate of is speed optimisation. Why should they have to worry about how long their masterpiece takes to load? Again, that gets in the way of creativity. Programmers can use all sorts of tricks like image optimisation, careful reuse of CSS/scripts, CSS sprites etc.

Quite apart from all this, there are practical considerations. Having multiple people working on a website can often result in changes being overwritten. I have had rarely worked on a reasonable sized website with a designer without having to re-write at least one chunk of code because they had either downloaded the entire site, changed it and put it back, overwriting my changes, or they had just been editing a file at the same time as me (in all fairness, I’ve overwritten their changes that way too).

Also, websites that have a lot of dynamic functionality use increasingly abstract frameworks (such as ASP.NET Web Forms) to deal with separating the design from the code. This makes things much easier and quicker (and therefore costs less to develop) for programmers, but it does mean that designers often can’t understand what they are looking at or how to make changes.

Now, I’m not saying that designers should never make websites themselves. Small businesses often just need a cheap website that is mostly static text and images and don’t want to have to pay for a programmer to do all the HTML/CSS properly, and in those cases, you could probably make a good case that most of what I said isn’t an issue. That’s fair enough, and if they need a small contact form or something then that’s probably not a major hassle for a programmer to do (assuming that they are hosting it somewhere that supports it). If your website is focused on functionality though, and you aren’t using an off-the-shelf solution, you are far better to keep a strict separation between coding and design.

Re-attaching SQL Server 2008 databases with Filestreams in a different path

Wednesday, July 7th, 2010

I’ve recently been moving servers and when I moved the databases, I was unable to re-attach them with a different path for the filestream folder.  The following blog post has a solution -

The Rambling DBA: SQL 2008 Filestream and Attach Database.

Finding missing foreign keys in Transact SQL (for MS SQL Server)

Tuesday, May 25th, 2010

When I put together a database, I generally use integer ID fields to reference one table from another and I usually have the referencing field ending in “ID”.  e.g if I have Customer and Order tables, Order will have a CustomerID field.

The problem is that in a big database, it is easy to forget to enforce the foreign key constraints for each and every one, so I thought it would be useful to have a query to find them.  After a bit of playing about, I have ended up with…


select table_name,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS cols where COLUMN_NAME <>'ID' and COLUMN_NAME like '%ID'
and TABLE_NAME not in('dtproperties')
and (select COUNT(*) from INFORMATION_SCHEMA.KEY_COLUMN_USAGE keys where keys.TABLE_NAME=cols.TABLE_NAME and keys.COLUMN_NAME=cols.COLUMN_NAME)=0
order by TABLE_NAME

You can add in extra tables to exclude in the “TABLE_NAME not in” clause. I’ve put dtproperties in there because that is the internal table that was showing up when I didn’t want it to.

I’ve tested this in SQL Server 2008, but I suspect that it should be good for anything from SQL 7.0 upwards.

Electricity Monitoring Part 1

Thursday, April 15th, 2010
This entry is part of a series, Electricity Monitoring»

This is a rather different topic to my usual posts.   A few weeks ago, I invested in an electricity monitor.  In case you haven’t come across them, they are little devices which monitor your electricity usage and display useful information, such as your current and historical usage.  Because I am a programmer, I did a bit of research to find one that I could access the data on and ended up with a Current Cost ENVI-CC128, although I did also need to get the USB Data Cable to connect it to my PC.

I was quite impressed with how easy it is to connect the transmitter (it just hooks around a specific cable going into the electicity meter (you can get extra transmitters – it can take up to three if you’ve got a 3 phase supply or multiple meters)).  The USB cable has practically no documentation though, other than a little information on Current Cost’s website and a total lack of understanding what I was asking for from their technical support people, which is a little odd, considering that they don’t actually supply any software with it themselves – you have to find it yourself or write some.

I worked out fairly quickly (with a little help from Googling other people’s experiences with the CC128) that the USB connection works as a simulated serial port which spews XML out when it receives a reading from the transmitter (usually every 6 seconds).  It also spews out totals every hour, but I haven’t bothered with those yet as I have a machine running the whole time, so I am currently just logging the readings to an SQL Server database as they happen.

I’ve also written a nice little program using ComponentOne’s charting component (C1Chart) so that I can specify a date/time range and get a graph of usage, either by individual reading or grouped by minute, hour, day, month or year (eventually!).  This has provided me with all sorts of interesting information, and given me a good picture of our electricity usage.

Entries in this series:
  1. Electricity Monitoring Part 1
Powered by Hackadelic Sliding Notes 1.6.4

Finding a table in a Linq to SQL DBML file in Visual Studio 2008

Monday, March 1st, 2010

One problem that can take up a lot of time if you are working in a large project with a lot of tables in the DBML database model file when using Linq to SQL in Visual Studio is finding the table in the diagram.  Control+F doesn’t work, and it can be a real pain to scroll around for ages.  However, the following article mentions a very simple solution – just use the dropdown at the top of the properties window!  Seems obvious, but I know quite a few people have been complaining about that for months!

Taken from Is there a way to find a table in a DBML file in Visual Studio 2008? – Stack Overflow.

Using sp_change_users_login ‘auto_fix’ to fix user/login

Sunday, February 21st, 2010

I have an occasional problem when moving a database from one server to another that although the users on the database are transferred correctly, the logins on the server are not. This is fair enough, as the logins are associated with the server, and the users are associated with the database. The problem is that there is no obvious way to re-create the logins correctly as if you try to do it, either the login won’t map to the old user, or it will complain that it can’t create a new user because it already exists.

One solution is to simply delete the old users and re-create, but this can be a real pain in the neck, especially if you have complex rights or can’t delete them because of the way things are configured. You can get around this with renaming users and re-creating and then switching things over and deleting the old ones, but this is all very tedious.

Fortunately, there is a stored procedure that will deal with the problem. First of all, create the new login without mapping it to a user. Once you have done that, open a query window in the appropriate database and run

sp_change_users_login ‘auto_fix’, ‘username

where username is the username that you want to fix.  It takes a split second to run, so you can do a whole load of them without too much hassle.

Windows Forms controls and the red X

Thursday, December 17th, 2009

I have been working on a project where certain controls randomly seem to come up with a red X and a red border around it.  I wasn’t sure what was causing it, but it turns out it is when an exception is thrown by code in the paint event.  For more details, see the following blog from sturmnet.org:  WinForms controls and the red X.

Exceptions Explained: NullReferenceException

Sunday, November 8th, 2009

This is the first on a new series of posts that I’m going to be doing on explaining various different exceptions, what they mean, when you might get them and how to avoid them.

The first one is the NullReferenceException, which usually comes with the message “Object reference not set to an instance of an object.”. This Exception occurs when you try to access an object reference which is set to Nothing.

First of all, you need to understand the difference between value types and reference types in .NET. With a value type, we only care about what data is stored within it. With a reference type, the actual instance of the type is important in itself. For example, we may have an Integer, which contains 10. Integers are value types, and there is generally nothing particularly different between one number 10 and another number 10 if they are both Integers, so they are effectively identical.

Reference types on the other hand are different. If we have two customers, and both of them happen to be called “John Smith”, we don’t want to treat them as being the same thing just because they have the same name. The other difference with reference types is that we can have an empty reference – Nothing (or null in c#).

In fact, behind the scenes, reference types store a location in memory of the instance. In older programming languages, such as C/C++, these were known as pointers, and you could actually access them just like a number and change the item that they were pointing to with arithmetic operators (+/-/increment/decrement etc.) This created a number of potential problems and so references were created to protect pointers from causing too much damage. References also the garbage collector to keep track of what is referencing an object instance so that the instance can be cleared up when it is no longer in use.

The NullReferenceException is thrown when you attempt to access an object reference which is set to Nothing. This can easily happen because as mentioned above, all variables of a reference type will be initialised to Nothing by the .NET framework if they have not been explicity set to something else.

For example,

        Dim c As Customer
        c.Name = "John Smith"

The second line in the above piece of code will throw a NullReferenceException as the variable c is still set to Nothing, and when the .NET framework attempts to access the Name field, it will find that the object does not exist.

This is easily resolved by setting c to whatever Customer you wish to use, or to a New Customer.