Category Archives: Knowledge Base

My GIT cheat sheet

I’ve finally made the leap from SVN to GiT as my solution for source control and so far I’m impressed, especially with how easy it is to maintain and create multiple branches of code.  Gone are the days of creating more than one branch at the same time leading to a world of merging pain.

2 things I came across though quite early on though;

  1. SSH seems to be much more stable than https
  2. and Git Bash is a great client once you learn the commands.

Needless to say there are lots of commands for GiT giving the user complete flexibility over their code base but so far I’ve managed to get by with this sub set of commands:

Retrieve a repository from Git Hub

git clone ssh/https location

Show the status of the current code branch

git status

Show the check in and revision status

git log –graph

Show all available branches

git branch -a

Switch to another branch

git checkout branchname

Create a new branch from the current branch

git checkout -b newbranch parentbranch

Commit any changes to your local repository

git commit -am “check in message”

Merge your branch back into the parent branch

git checkout parentbranch

git merge –no-ff newbranch

Push changes back to the main repository (Git Hub)

git push origin parentbranch

Get latest changes from the main repository into branch

git pull origin branchname


A Simple Defibrillator Class in C#

Timeout Defibrillators are common in the ASP.NET world, where there is often a requirement to keep a session alive during a period of inactivity.  However the same can be said about the windows application domain.  For example, assume that user enters an area of the application which serves up some specific data.  While the user has this screen open, it should be locked to all other users so that the data cannot be modified.  But what happens if the user decides to go to lunch with the screen open preventing all other users from working.

In scenarios like this it would be nice to have a simple class which when invoked starts a timeout process for long periods of inactivity.  When this time out is reached an event is raised to the calling object which allows the application to release the lock.  Additionally there is a method in the class which can be called by the parent object to reset the timer if there is some form of activity on the screen.

Below is my simple Defibrillator class and below that an explanation of the key points of this class and how to use it.

Defibrillator Class

So the basics of this class are:

  • A delegate and event have been created at the top of this page which can be subscribed to by the calling object.  This allows us to raise an event to the parent once the time out has been reached.
  • The constructor allows the user to pass in the time is seconds which should be observed before the timeout is reached.
  • The Start method is called when we are ready to commence the timer.  Note that I have set the Interval between ticks to be 1 second.  The timer object allows us to set a call back method which is invoked after every tick (1 second interval in this case)
  • The Reset method allows us to Reset the timer.  This would probably be called if the parent registers user activity.
  • The TimerProc method is called after every tick of the timer.  Here I am performing a check to see if the timeout has been reached.  If it has the timer is disposed and the event raised back to the Parent.


To use the class, simply create a Form which has a reference to the Defibrillator class and add code similar to below:

Invoking the class

Here I am creating an instance of the class with a 10 second timeout.  I am also subscribing to the TimeOut Reached event which will call the method dt_TimeOutReached when the time out completes.

All that’s left is to start the Timer – dt.Start()



C# – Importing a csv into a strongly typed Dataset

Often there will be a requirement to import data into your application and more often than not, when the question is asked ‘so what format will the data be in that you need to import?’ we are replied to with those 3 little letters CSV when what we really want to hear are the letters XML.

However if you can tie the client down to the format of the CSV file then all isn’t too bad.  So heres an example of how to read a csv file and import the data into a strongly typed dataset.

Step 1 – Create our demo project

First create a new Windows forms project and on the form add the following;

  • button called btnOpen
  • dataGridView called dataGridView1
  • openFileDialog called fdChooseFile


Our basic form


Step 2 – Create a strongly typed dataset

ok first we have to know the format of the incoming csv file before creating the dataset.  One this example I have created a simple csv file called fileimport.csv with the headings ‘ID’, ‘Firstname’, ‘Surname’ and ‘Address’

Quick CSV file with headings

Next add a new Dataset and drag a DataTable from the Toolbox onto the designer.  The columns of the dataTable should match those in the incoming CSV file so you end up with something like:

Creating the strongly typed dataset

Step 3 – Reading the CSV File

ok so we have a sample csv file and a strongly typed dataset which contains a data table matching the same columns as out csv file.  Now for the code to read the CSV file and populate the DataTable.  For this we will use the Microsoft Text Driver and the code will be something like;

Method to read the csv file and fill the datatable

This method accepts the datatable to fill and the path and filename details of the csv file.  Don’t worry I will wire all this in in the next step but I wanted to first show the code at the heart of this post.

Using the Microsoft Text Driver and an odbcDataAdapter we can query the csv file directly, assuming we know what we are looking for.  then using the Fill method of the adapter we can just populate the datatable and supply this as the data source for the grid view.  simple.

Step 4 – Bringing it all together

The last part is to load in the csv file in the first place and pass it too the ReadData method above.  For simplicity I have thrown all the code into the click event of the button (as shown below).  Take note of wheer I’m creating instances of the dataset and datatable  though before calling the ReadData method

code to load the csv file on the button click event


Leave a comment

Posted by on January 23, 2012 in C#, Knowledge Base


Unlock the ‘sa’ account in SQL Server

Just thought I would add this invaluable bit of SQL as it comes up time and time again here.  You only get a couple of attempts to give the correct password to the sa account when loggin into SQL Server before the account becomes locked.

If this happens hopefully you will have a backup admin account or able to log in via integrated authentication.

If this is the case, log in and open a new Query window and type the following:


Job done, the sa account is now unlocked ready for someone to come along and lock it out again!!


Project file contains ToolsVersion “4.0”, which is not supported by this version of MSBuild

Recently I came across this error when calling MSBuild from the command line and building a project which I thought was targeted at framework 3.5.  So why was it trying to reference .NET framework tools version 4.0

Well the answer was that I developed the project in VS2010 but targeted framework 3.5.  When a project is developed in VS2010 the project file is created with a default ToolsVersion reference to 4.0.


Open the csproj file and right up the top you will notice something like

<Project ToolsVersion=”4.0″ DefaultTargets=”Build” xmlns=”“>

To remove the warning message, just edit the toolsversion to be the version of the framework you are targeting e.g. 3.5


1 Comment

Posted by on September 14, 2011 in Knowledge Base


Msbuild Error MSB1008: Only one project can be specified

If you receive this error when running the MSBUILD command line then you probably have spaces when specifying the location of your project

e.g. msbuild.exe c:\This is my project\project.csproj

Leave a comment

Posted by on September 8, 2011 in Knowledge Base