Far Away Developer

Sebastien Lachance

Archive for March, 2008

The importance of database versionning

Posted by Sebastien Lachance on March 12, 2008

2-3 months ago, I have deployed the application I was working on the client. Since then a lot of changes have been made and I did not work on this project. The database changed significantly but the sql script have not been updated with the latest changes. Now, I have to get back on the project to make an update to the client. I can generate a new set of scripts to create a new database, but how am I suppose to update the production database …

Before I left, I gave instruction on how to version every changes to the database. I wanted to have scripts with every changes that have been made and then run them on the client on future update.

Let’s see the pros and cons of not doing so :

PROS :

  • Save time when developing

CONS :

  • No way to easily update an existing database
  • Loose time trying to figure out what is changed
  • No confidence that you will update the existing database correctly
  • No way to get back in time if needed

Please, version your sql script! It will be much easier for those doing the futur work.

Posted in Agile, Continuous Integration, Learning | 1 Comment »

Cannot have multiple items selected in a DropDownList.

Posted by Sebastien Lachance on March 8, 2008

Cannot have multiple items selected in a DropDownList.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error:

Line 253:            total = parseFloat(lblTotal.innerHTML.replace('$', '').replace(',', '.'));
Line 254:            fBudget = parseFloat(budget.replace('$', '').replace(',', '.'));
Line 255:            var lblWarningContract = document.getElementById('<%= lblWarningContract.ClientID %>');
Line 256:
Line 257:            if (total > fBudget)

I spent at least one hour figuring this out. The Source Error  does not contain any valid information. The solution is : you should never use the same item twice on two different dropdownlist.

ListItem item = new ListItem(" -- Select one -- ", "-1");

ddlLoadingContact.Items.Insert(0, item);
ddlUnloadingContact.Items.Insert(0, item);

A ListItem have a property called Selected that tells which one (the item) the dropdownlist should display as selected. If you use the same ListItem in more that one dropdownlist and you select this item in the DropDownA and a different item in DropDownB. The DropDownB will have two ListItem with the Selected property set to true. Since this is the same item in both dropdownlist.

ddlLoadingContact.SelectedValue = "-1"; //item will have the Selected property set to true
ddlUnloadingContact.SelectedValue = "John";  //another item will have the Selected property set to true. And both are contained in this dropdownlist.
 
 

Posted in .NET, ASP.NET | 4 Comments »

My experience as a remote worker

Posted by Sebastien Lachance on March 6, 2008

You may not know, but I am a full time web worker since February 2007 and I am loving it. I followed my girlfriend to his new job in mechanical engineering located in the “Beauce” area in the province of Québec (1 hour from Québec City). But let’s make a point clear. It was not as easy as it sounds. It takes a lot of discipline and you may find that you just can’t do it. I have had many friends who were not able to work from home. For me, it was easy since it’s a childhood dream. I have gone through 3 phases.

The first one is the “That’s easy” phase. During the first 2 months, everything seemed so easy. I was very productive and enjoyed every minutes working from home. This is also the phase were you work more than you are supposed and keep no free time. You have the impression you can achieve anything.

I called the second phase : “I need to check everything around the house to be sure nothing changed.”. In this phase, everything disturbed me. I started to feel lonely and was wondering if I made the right choice. During this 6 months phase I had a hard time concentrating on my job. It’s also the time we were building our new home. During that time, I never took a day off except the day we moved in. I was exhausted, stressed and lost. We had problems with contractors. The price we anticipated was a bit higher due to the angle of the lot we bought. To make things worst, I started working on a new project requiring me to work with Microsoft Dynamics (until you used the supplied API you can’t imagine how frustrating of an experience it is). But I have gone through it.

Now, I am in the third phase. I called it the “Rebirth phase”. I restarted my old habit of learning as much as I can. I have solved my concentration problem. I feel a lot more happier and a lot more in health. I started to really enjoy working remotely and I am sure I am as productive as I was before. I am now fully happy with it. And I have new projects for my region…

Posted in Blogging, General, Programming | 2 Comments »

I am now available to hire !

Posted by Sebastien Lachance on March 3, 2008

I am now available to work on small contracts for now. I also want to work remotely. If you are interested, just let me know via the contact form.

HIRE ME !

Posted in Blogging, General, Programming, Project | No Comments »

WHILSOF : Getting started with NHibernate

Posted by Sebastien Lachance on March 3, 2008

Without digging in too much detail about NHibernate, I will presume you are familiar with what this O/R Mapper can do.

The application configuration file :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="hibernate.dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="hibernate.connection.connection_string">Server=.SQLEXPRESS;Initial Catalog=RecipeHelperTest;User Id=recipeuser;Password=recipeuser;</property>
      <mapping assembly="RecipeHelper.Domain" />
    </session-factory>
  </hibernate-configuration>
</configuration>

This is standard stuff that you can find in the documentation. One interesting point however is the mapping. You can specify where your domain object to be persisted are. This will allow you to not worry about specifying them in code.

Creating a mapping file :

To be able to persist your entities, you’ll need to create a mapping file. In my opinion, this is the hardest thing to learn about NHibernate. But don’t worry, it is well documented.

The strategy I am using is one file per entities, in the same assembly. I also use the same name with the extension “.hbm.xml”. The trickiest part is that you need to set the Build Action to “Embedded Resource“. Once all this is completed you can now start writing your mapping information :

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RecipeHelper.Domain" namespace="RecipeHelper.Domain" default-lazy="false">
  <class name="Recipe" table="Recipes" >
    <id name="ID" column="ID" type="int" access="field.lowercase-underscore">
      <generator class="native" />
    </id>
    <property name="Name" column="Name" type="string" not-null="false"/>
    <property name="Reference" column="Reference" type="string" not-null="false" />
    <property name="Rating" column="Rating" type="int" not-null="false" />
  </class>
</hibernate-mapping>

Preparation for using NHibernate :

The biggest performance hit is the creation of the ISessionFactory. For this reason, it should only be instantiated once. I created a singleton that will allow me to have access to a single session factory.

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace RecipeHelper.Domain
{
    public class NHibernateConfig
    {
        private static ISessionFactory _sessionFactory;

        static NHibernateConfig()
        {
            Configuration config = new Configuration();

            _sessionFactory = config.Configure().BuildSessionFactory();
        }

        public static ISessionFactory GetSessionFactory()
        {
            return _sessionFactory;
        }

    }
}

Conclusion :

This isn’t a complete tutorial to get started with NHibernate but should cover the essential steps to prepare your project to use it.

Posted in Agile, Learning, Tools | No Comments »