SQL Migration to Azure

April 17th, 2012 No comments

I’ve been playing about with Azure at work recently to test it out and see if it will work as we need for clients. For the most part it has been blindingly easy to set up. But one thing I had a few issues with was migrating my SQL data to SQL Azure (on the Azure platform there are 2 database types, rather helpfully named Windows Azure – which is a noSQL database and SQL Azure – which is based on SQL server).

As we have developed a site using Umbraco, we wanted to package the database and just restore it on Azure. You can connect to SQL Azure by SQL Server Management Studio (if you do, be sure to install SSMS 2008R2 as 2008 will not work properly) but you can’t backup and restore an Azure DB using this method. Enter the SQL Azure Migration tool, which is very simple to use. You connect to your SQL server, choose your database, then connect to your SQL Azure instance and select which DB you want to restore to. Easy life. One gotcha though: You can only restore SQL server 2008 R2 database. If you try an older DB you will get errors, so try and upgrade before even considering Azure.

Returning a default with generics

March 28th, 2012 No comments

Today I was working on a generic method which gets a querystring and converts it. If the querystring exists, it would convert the type and return it. However, I’d also need to return a default if the querystring doesn’t exist. As it was a generic method, I couldn’t rely on just returning a null as if the type was an integer, this wouldn’t work (assuming not a nullable integer).

I disovered this nifty little method though:
return default(T);

Lovely, it will then respond appropriately, if an integer, it would return a 0, if a string, a null.

Categories: asp.net, C# Tags: , ,

TestCaseSource in Nunit 2.5

February 29th, 2012 No comments

Recently, one my team mates discovered the TestCaseSource attribute in Nunit 2.5. I have been using the TestCase attribute for a little while. It enables you to tes multiple inputs with one test:

[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

This is useful for various reasons, mainly that you don’t have to write a separate test for each input. TestCaseSource is a different way of doing this by allowing the user to build up an IEnumerable of test cases and just add that to the test.


[Test, TestCaseSource("DivideCases")]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

static object[] DivideCases =
{
  new object[] { 12, 3, 4 },
  new object[] { 12, 2, 6 },
  new object[] { 12, 4, 3 }
};

This is helpful as you won’t have a load of testcase attributes at the top of each test, and you could reuse this data. Lovely!

Upgrading Sitecore causes Global.asax to not work

February 29th, 2012 No comments

AAAAAHHHH! This fix, I hope, will save you a lot of time. Recently we have been upgrading some clients to the latest Sitecore. Generally that works fine, however, on re-compile, then running the application, I get a nasty StructureMap Exception Code: 202 (we use this lovely little nugget for IoC). Panic ensues. You check everything, it’s all in place. You check the Global.asax in Visual Studio (where we kick off Structuremap and any application wide methods), it has all the code there. And there’s the problem. Visual Studio opens global.asax.cs by default, which is correct really, code should really only be in there. However, if you open the global.asax file in your favourite text editor, you see the issue. Sitecore replaces the global.asax file with a default, which has default, empty code and methods in it! It looks like:

<%@Application Language='C#' Inherits="Sitecore.Web.Application" %>
<script runat="server">
public void Application_Start() {
}

public void Application_End() {
}

public void Application_Error(object sender, EventArgs args) {
}
</script>

What this means is, although Visual Studio sees all your code in global.asax.cs, that code is not running because it isn’t even referenced by the global.asax in the first place, it should look something like this instead:
<%@ Application Codebehind="Global.asax.cs" Inherits="YourSiteAssembly.Site.Global" Language="C#" %>

Infuriating? Very! Just keep an eye on that global.asax file! I hope this saves you some time and a lot of pain.

Sitecore desktop freezes

February 21st, 2012 No comments

While working on a site recently, I noticed that trying to get to the Desktop version of Sitecore, it would get stuck just in a request state, nothing happening. This was always after logging in, the Sitecore login page itself worked fine. It would also not log any issues in the log files. The thing that fixed it was to make C:WindowsTemp a writable folder for the IIS user. Almost immediately it worked. Phew!

I hope this helps :) .

What’s that duck for?

February 12th, 2012 No comments

I’ve written about this before in my last, not so focused blog, but I’ll write it again. There are a few simple non-programming programmer rules I like to adhere to. These would be things like KISS (Keep It Simple Stupid) etc. Another lesser known one of these is Rubber Duck Debugging.

The duck on my desk

When you hit a conundrum while coding, it is very easy to sit and suffer, draw diagrams etc. Many (including myself) tend to internalise this and not speak it. Usually, if you then ask another programmer, by the time you have explained the problem you have worked it out because you have externalised the issue.

Rubber duck debugging gets round this (sort of). You get a rubber duck (you should always have one on your desk) and when you hit a conundrum, you pick the duck up and you explain the issue you are having. By doing this, you externalise the problem and it can really help. It feels daft, but it can really cure the issues of Cognitive Dissonance and make you feel much better.

Of course, asking someone else helps even more, but if they’re not about/you feel stupid asking because it feels like a simple issue, this is a great back up.

And that, ladies and gentlemen, is why I have a rubber duck on my desk.

Supersized Jquery library

February 12th, 2012 No comments

I keep saying this: if .net and C# (or just back end technologies), then HTML, Javascript and CSS (front end technologies) are my mistress. I love to dabble with these lovely pieces of simple but great technologies.

One of my latest things is to take a library off Github (let’s not forget Bitbucket too!) and start playing with it. Recently, I needed a way of easily animating a background on a page and by chance stumbled across the Mishkin’s site: http://mishkins.co.uk/. Apart from ogling the food, the background transitions are amazing, even if you have low resolution images. I decided to peruse the source code to find they use a Jquery library called Supersized, a library which allows backgrounds to be loaded and displayed like a slideshow with lovely effects. It even handles stretching the image as you need and various other options.

Have a go. I love the way the web has progressed.

Remotely disconnect an RDP session

January 25th, 2012 No comments

If you find someone doesn’t log off their session after using RDP and just disconnects, you may need to regularly ask them to log off, or force a log off. But you can also log off their session remotely by doing the following in your command line (this should work in your dev environments internally, it may not work on servers outside your domain etc.).

qwinsta /server:

You get results with who is logged in, a state and an id (session Id). Just remember the id.

Then type:
logoff /server:

Categories: General Tags: , ,

Fonts and MsDeploy

January 12th, 2012 No comments

While trying to deploy a site this morning using MsDeploy triggered by my build server, most worked well, apart from the fonts I was using being pushed as well. Some fonts are called from the CSS and need to be in there too. These didn’t upload with the deploy at all. Well, one did, but I have 4. I realised that each of these files need to be set to be Content in Visual Studio and hey presto, fonts will go in the build.

This should work with other files if you’re having problems with them not being in the build.

Categories: asp.net, Deploy Tags: , ,

Setting up SSH and Git on PC

January 11th, 2012 No comments

Today at lunch, the tech team at work sat down for a lunch at learn to work out Git, which we are currently migrating to. We had a few learning issues with setting up SSH keys within Git Extensions, so I thought I’d write my findings down here.

For this, you’ll need to download Pageant and PuTTYGen from the PuTTY download page.

Once done with that, open PuTTYGen and click “Generate”. You’ll then need to run your mouse around until you have a random key. After this is done, click “Save private key” and save the file somewhere. At the top, there will be a Public key you can copy starting with ssh-rsa, copy all of this string.

Open Pageant (it may open in the System Tray, so if it doesn’t appear, just search for it there). Click to Add Key and select the private key you saved earlier.

Now log into your Github account and go to your account settings. In the account overview, you should find “SSH Public Keys”. Add a new public key, you can call the title anything. Then paste the public key you copied earlier into the “Key” field. You should now be set up to go with SSH.

Categories: Git, Version Control Tags: , , , ,

Switch to our mobile site