Dutch social security number check


For a Dutch customer I currently work for, I dealed with an incorrect social security number check (in Dutch: elfproef voor BSN’s/burgerservicenummers). After checking out the Internet for the correct definition of Dutch social security numbers (e.g. Burgerservicenummer – Wikipedia), I created the next check in C#:

string cleanBsnNr = bsnNr.Trim().Replace(".", "");

// A BSN consists of 9 characters ...
if(cleanBsnNr.Length != 9) return false;

// ... all being numeric and not resulting in a 0 when converted to a number ...
long l;
if(!long.TryParse(cleanBsnNr, out l)) return false;
else if(l == 0) return false;

// ... the number must be validatable to the so-called 11-proof ...
long total = 0;
for(int i = 1; i <= 9; i++)
{
    // 11-proof voor BSN's: (9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + (-1*I)) % 11 == 0
    int number = Convert.ToInt32(cleanBsnNr[i - 1].ToString());
    int multiplier = 10 - i;
    if(i == 9) multiplier = -1 * multiplier;

    total += number * multiplier;
}

// ... not result in a 0 when dividing by 11 ...
if(total == 0) return false;

// ... and not have a modulo when dividing by 11.
return total % 11 == 0;

Good luck when you should build one for yourself. Checking your own built check can be done using this website with generated BSN’s (or your own, of course) by Menno Wilmans.

TFS 2008 and SQL Server 2008 on one machine


Some days ago, I installed Team Foundation Server 2008 on one box with SQL Server 2008. Everything seemed to function well, but since the installation of TFS 2008 ‘at least one service did not start up’.

Digging into the event viewer, I discovered TFS Scheduler did not function well. It did not start up because it could not find the TFSIntegration database. The reason? It starts up in racing condition with MS SQL Server. To solve the problem, I added a dependency for the TFS Scheduler service on MSSQLSERVER. Problem solved!

The link on how to perform this task: http://support.microsoft.com/kb/193888. If you need more information, send me a message ;)

Alternative SMTP server

Yesterday I discovered that about half of all emails sent using my ISP’s SMTP server are rejected by my recipient’s mail servers. The reason: since a long while my personal ISP, Online (former Orange, even more former Wanadoo) is blacklisted for spam reasons.

As I understand when surfing the Internet for this problem, many users suffer from the same problem. I decided it was time to do something myself, as I cannot rely on the SMTP server anymore. Therefore I looked for a reliable SMTP relay server (paid, to prevent myself to overcome the same problem again). That particular relay server must support the Exchange Server’s smart host on an alternative SMTP port, since Online has closed port 25.

Since a couple of hours I use the mail relay service of DNSexit for just a few bucks per year. All functions wonderful, my mail arrives again (not unimportant). I also tried using SMTP2GO, but unfortunately they do not support an Exchange Server smart host.

Multicast delegate invocation

Today I remembered the need to blog again. It sounds weird, but it isn’t :) … A while ago I ran into a failing multicast delegate and decided to blog it. Since I ran into one again today and having to look up my previous solution again the hard way, I discovered I should have done it immediately. Check the story below:

Multicast delegates are great. Today I had to implement a custom user control (insurance cost calculation) with several child controls (one for each prospect) which depend on each other (e.g. parent and children). I use a delegate to notify the parent control that one of it’s children selections has changed.

The original call:

public event EventHandler SelectionChanged;

/// <summary>
/// This method cares for correct event handling
/// </summary>
private void OnSelectionChanged()
{
  // The SelectionChanged event will be null if there are no subscribers.
  if (SelectionChanged != null) SelectionChanged(this, EventArgs.Empty);
}

For some dumb reason I ran into a NRE using the delegate. Guess what happened? Subsequent delegate subscribers did not get fired anymore. The reason is that a delegate that fails for some reason, fails entirely. After researching the problem again, I changed the code provided hereabove with the following piece of code:

public event EventHandler SelectionChanged;

/// <summary>
/// This method cares for correct event handling, including the protection against
/// failing individual event subscribers
/// </summary>
private void OnSelectionChanged()
{
  // The SelectionChanged event will be null if there are no subscribers.
  if (SelectionChanged != null)
  {
    try
    {
      Delegate[] list = SelectionChanged.GetInvocationList();
      foreach (Delegate del in list)
      {
        try
        {
          // Only the current subscriber will file, the rest of the delegate's
          // invocation will proceed as normal.
          EventHandler handler = (EventHandler) del;
          handler(this, EventArgs.Empty);
        }
        catch { }
      }
    }
    catch { }
  }
}

Cheap ASP.NET web hosting

Since a couple of months I moved my hosting packages to a new host, DIGITALiBiz. The reason I moved in to them is their incredible low pricing considering what they offer. I currently have ASP.NET 3.5 hosting, 350GB disk space and 5 SQL Server 2005 databases of 250MB each. Who can beat them???

After some months of working with DIGITALiBiz, I can say that they have an excellent support team and a very reasonable performance. Definitely recommended!

Curious? Have a look at DIGITALiBiz.

Technorati tags: