DbUp
DbUp is an open source .Net library that helps making database changes in a deployment an awful lot easier.
The docs for DbUp can be found here, however DbUp is so easy to use there isn’t much to them.
Setup
First thing to do in order to get DbUp working is to start a new console application then install the DbUp nuget package.
Install-Package DbUp
Any SQL scripts that you want to be run as part of the application need to be added to the project and set their build action to be an embedded resource. While DbUp keeps a track of the scripts it has run, I find it useful to name the scripts sequentially to help keep them organised.
In Program.cs you will need to add the code from the docs and then you are ready to run the console application. There is a debug conditional in the code with a Console.ReadLine() if there is a failure in the application so you can see the error message. It’s probably me being overly cautious but I also like to put the same debug conditional in for successes as well just so I can review those messages if needs be.
For deployments, all you need to do is run the console application in each environment by using a Powershell script for example.
Benefits
Just as automated code deployments are important, it’s also important to automate database changes. As its likely that database changes are less common that code changes, it can be very easy to forget to make any required changes if they have to be done manually.
While there are other tools such as Redgate’s SQL Compare and they are awesome, for keeping a database in a correct state for deployments I’m a big fan of DbUp. Rather than just comparing two databases I like to be in control of the changes and write my own scripts.
Another very useful benefit of this approach is that the database scripts can be stored in source control.
Given that DbUp is free and so easy to setup then I think this is a great tool to be part of deployments.
What I learned from The Goal
People have been telling me for years how good a book The Goal is and now I’ve finally read it.
Format of the book
The Goal is a management book explaining the Theory of Constraints and how it can be applied to a manufacturing plant. Rather than just explaining the concept, the book is a novel following a stressed out manager trying to save his plant from closing.
What is the goal?
One of the important lessons that I took away from the book was to remember what the goal of an organisation is. For many organisations this is to make money and if the actions aren’t helping towards the goal then they probably aren’t the right actions.
For example reducing costs in itself is not the goal, especially if it comes at the cost of sales.
The goal puts forward a simplified method of measuring yourself against your goal. It consists of three measures; throughput, inventory and operational expense. An organisation will want to raise throughput (revenue) while reducing inventory (money in work in progress) and operational expenses.
Theory of constraints
The book explains how the plant manager can help the plant by looking at where the bottlenecks or constraints are in the plant and work to maximise their efficiencies. Many people in the company were looking at the wrong performance indicators. For example they were focusing on cost per part and ensuring that all staff were busy all of the time.
However, its important to identify the system’s constraints. As the book explains, an hour lost on a bottleneck resource is an hour lost to the whole system due to its impact on throughput. It is much more important to have an optimised system rather than locally optimised parts of the system.
The approach to a problem
A system’s constraint isn’t always going to be a physical resource. It could be external, personal or a process so its useful to have a process of how to deal with different bottlenecks. The process that the plant manager comes up with is 5 steps to deal with a constraint.
- Identify the constraint
- Decide how to exploit the constraint
- Subordinate everything else to the constraint
- Elevate the contraint
- If the constraint is no longer a constraint then go back to step 1
Once changes have been put into place to help the bottleneck it is important to not let inertia stop further improvements. If an action helps to improve throughput it doesn’t mean that the action will always be the right action. Circumstances change and fighting the inertia of processes can be difficult. Its important to be able to respond to new challenges and opportunities.
How I found the book
When I first started the book I didn’t enjoy that the book was written as a fiction novel. It seemed that the information could be given in a much more succint way. I also didn’t enjoy reading about the main character’s marital problems.
However after finishing the book I do think that the style did help the lessons learned to stick. I do think that there is a lot to be learned from this book but I think the main thing I learned was to look after my wife, work is important but some things are more important.
My first programmed Arduino circuit
My last Arduino lesson was the first one where I had to build a circuit but also control it with a programmed sketch.
The Circuit
In this circuit there were three LEDs, resistors and a push switch. When the circuit has power the green LED is lit, but when the push switch was pressed the two red LEDs flash.
To achieve this, the LEDs and the switch in this circuit had to be connected to the pins on the Arduino. This allows the Arduino to control if the LEDs have voltage going to them or not. Pins 0 and 1 are used for connecting to the computer so its useful to start at pin 2.


Writing the Sketch
Each sketch needs two main functions in order to work;
void setup(){
}
void loop(){
}
Setup is run once when the program starts and unsurprisingly loop repeats throughout the program running. In the setup of the sketch the numbers of the used pins and if they are to be used as input or an output.
pinMode(5, OUTPUT);
pinMode(2, INPUT);
In the loop you can check if the switch is pressed down by using the digital read method and passing in the pin number of the input.
int buttonPressed = digitalRead(2);
As it is a digital input the value from digital read can be asigned to an int as it will return 0 or 1.
Similarly, digital write also takes a pin number as an argument but also if you want the pin to be set to HIGH (1) or LOW (0).
digitalWrite(3, HIGH);
My Full Sketch
int switchState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
switchState = digitalRead(2);
if(switchState == LOW){
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
else{
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250);
}
}
Apart from learning how a sketch is built and what happens when it runs, this lesson also taught me more about resistors. Here the example circuit had each LED connected to the resistor on the ground side of the circuit. As long as the circuit is wired in series it doesn’t matter where the resistor is connected.
Prefix
I’ve been playing with a new tool from Stackify recently called Prefix and so far I’m really impressed. Prefix is a free .Net profiler that shows all the web requests, sql queries and service calls etc that run through your local IIS.
Being able to see how many service calls and how long SQL queries are taking per request can be extremely useful to helping solve performance issues.
Setup
Setup is very easy, especially if you are using local IIS. A quick install and then Prefix will configure itself to start profiling IIS. If you are using IIS Express then you need to setup the Stackify HTTP module manually. Instructions can be found here.
Its been pretty useful to keep the Prefix UI open all the time on my second screen. Not as something I refer to constantly but its there when I need it if something takes a while to run. As of yet I’ve not noticed it having any negative effect on my laptop’s performance.
Logging
If you want to view related logging for a call in Prefix, you will to get relevant Nlog/Log4Net Stackify nuget packages. It can be really useful to see only the relevant logging messages to a specific call rather than searching through a whole log file. If you leave the Stackify API key blank then the profiler will only run locally.
Supported Frameworks
Currently Prefix supports more than 30 .Net libraries. I was pleased to see that they are supporting a range of really useful libraries such as MVC, Nancy, SQL Server, Mongo and Redis just to name a few. Furthermore, most aync calls are also supported.
With site performance being so crucial, its really helpful find backend issues before they even leave the development machine. The fact that it’s free doesn’t hurt either. To get Prefx you can download it from prefix.io.
Update
I’ve updated this blog post just to show a nice little tip that you can do when using Prefix. You can just leave the API key blank in your web.config and the profiler won’t run on the server. However, if you don’t want unused libraries deployed to the server you can exclude them from your nuget package in your nuspec file.
For example;
<files>
<file src="bin\**" target="bin\" exclude="StackifyLib.NLog.dll;StackifyLib.log4net.dll" />
</files>
My first Arduino circuit
I just built my first circuit with my Arduino!
I’m working my way through the lessons of the official Arduino starter kit and the second lesson shows you how to create a circuit by using the breadboard.
One of the things that I really like about this kit and the projects book is that it doesn’t just tell you how to set the circuit up, but explains why and what is happening within the circuit.
For example, it explains the difference between current and voltage. Current is the amount of energy flowing past a point in the circuit and volts is the difference in energy between one point in the circuit and another. This didn’t mean an awful lot to me, however they give a very useful analogy of rocks rolling down a hill. The amount of rocks is like the current and the height of the hill is like voltage.
In this first circuit, the parts that are used are a resistor, LED and push button. It was interesting to only be using the Arduino as a power source rather than actually programming anything. While only being a basic circuit with one LED it felt awesome to make something physically happen.

After successfully getting the LED to light up when the butotn is pushed, the lesson moves on to setting up two switches in series. When the switches are connected in series both switches have to be pressed in order to complete the circuit and make the LED light up.

The next step was to connect the switches in parallel rather than series. This meant that if either button was pressed then the circuit was completed. This was really taking me back to my old electronics lessons at school.


The lesson ended explaining Ohm’s Law.
Volts = Current * Resistance
By using Ohm’s Law you can calculate the voltage, current or resistance in a circuit. This lesson used 5 volts and a 220 ohm resister. So 5 / 220 = 0.023 amps or 23 milliamps. Apart from enjoying making my first circuit, this lesson taught me that there is a LOT to learn about electronics.