Archive

Software Development

In certain circumstances, you might find yourself with a need to install SQL Server Express on one of your Windows Azure worker roles. Exercise caution here though folks: this is not a supported design pattern (remember, a restart of your role instance will cause all data to be lost).

It was however exactly what I needed for my scenario and I thought I’d share it in case it serves a purpose for you.

There are a couple of approaches you can take, of course, one of which is ‘startup tasks’ specified in the service definition files. However, these offered me limited configuration options because I needed to customise some of the command line arguments being passed to the installer based on values from the Role Environment itself.

The trickiest part was actually figuring out the correct command line parameters for SQL Server 2008 R2 Express, which to be honest wasn’t that fiddly at all. Here are the parameters you’ll need:

/Q/ACTION=Install/FEATURES=SQLEngine,Tools /INSTANCENAME=YourInstanceName
/HIDECONSOLE /NPENABLED=1 /TCPENABLED=1 /SQLSVCACCOUNT=”.\YourServiceAccount\” /SQLSVCPASSWORD=”YourServicePassword” /SQLSYSADMINACCOUNTS=”\.\ADMINACCOUNT” /IACCEPTSQLSERVERLICENSETERM S/INSTALLSQLDATADIR=”FullyQualifiedPathToFolder”

In the parameters above, we’re specifying a silentinstall with the /Qparameter, installing the SQL Database Engine and Management Tools (basic) with the /FEATURESparameter, setting the instance name, enabling named pipes and TCP, while setting service accounts and specifying the SQL data directory.

The next part then, is to actually build this as a command line and execute it in the cloud environment. How do we do this? Simples: we use System.Diagnostics to create a new Process()object and pass in a ProcessStartInfoobject as a parameter:

var taskInfo=new ProcessStartInfo
{
FileName=file,
Arguments=args,
Verb="runas",
UseShellExecute=false,
RedirectStandardOutput=true,
RedirectStandardError=true,
CreateNoWindow=false
};
//Starttheprocess
_process=new Process(){StartInfo=taskInfo,EnableRaisingEvents=true};

For good measure, we’ll also redirect the standard and error output streams from the process so that we can capture those out to our log files:

//Logoutput
DataReceivedEventHandler outputHandler=(s,e)=>Trace.TraceInformation(e.Data);
DataReceivedEventHandler errorHandler=(s,e)=>Trace.TraceInformation(e.Data);

//Attachhandlers
_process.ErrorDataReceived+=errorHandler;
_process.OutputDataReceived+=outputHandler;

Then, we’ll execute our task and ask the role to wait for it to complete before continuing with startup:

//Startprocess
_process.Start();
_process.BeginErrorReadLine();
_process.BeginOutputReadLine();

// Wait for the task to complete before continuing...
_process.WaitForExit();

Stick all of that into a method that you can re-use, and don’t forget to add parameters called fileand args(strings) that contain the path to the SQL Server Express installation executable and the command line arguments you want to pass in.

How to build your command line argument

If you’re wondering why I didn’t hardcode my command line options, it’s because up in Azure, the standard builds for web and worker roles don’t come preloaded with any administrative accounts – you have to specify those during design time. I actually ‘borrow’ the username of the Remote Desktop user (which is provisioned as an administrator for you when you ask to enable Remote Desktop).

I actually end-up with this quick-and-dirty snippet:

stringfile=Path.Combine(UnpackPath,"SQLEXPRWT_x64_ENU.exe");
stringargs=string.Format("/Q/ACTION=Install/FEATURES=SQLEngine,TOOLS/INSTANCENAME={2}/HIDECONSOLE/NPENABLED=1/TCPENABLED=1/SQLSVCACCOUNT=\".\\{0}\"/SQLSVCPASSWORD=\"{1}\"/SQLSYSADMINACCOUNTS=\".\\{0}\"/IACCEPTSQLSERVERLICENSETERMS/INSTALLSQLDATADIR=\"{3}\"", username,password,instanceName,dataDir);

So, ultimately, you’ll then want to wrap all of this up in to your role’s OnStart() method. Include a check to see whether SQL Express is already installed, too.

And, if you’re stuck trying to debug what’s going on with your otherwise silent installation, SQL Server Setup Logs are your friend. You’ll find them by connecting to your role via Remote Desktop and opening the following path:

%programfiles%\Microsoft SQL Server\100\Setup Bootstrap\Log\

Enjoy!

Slides everywhere, but not a coherent flow in sight! :)

Way back on 11th June 2011, I was lucky enough to be invited to present my session – “Getting Started in .NET” – at the DDD Southwest 3 conference. I remember thinking, “gosh, I’d really love to speak at one of these events but I missed the deadline for submitting sessions”. So, I pinged an email over to Guy Smith-Ferrier and asked him if they needed any help, thinking maybe they’d want room monitors or other volunteers to ferry folks around. As it turned-out, Guy actually still had two slots to be filled on the ‘Getting Started’ track. And this is how my presentation was born…

Nervous? Me?

It was to be the first training session I’d ever given on a topic such as this, so I was both very excited and a little nervous (geeks can be so nit-picky!).

Fortunately though, the bunch of folks that attended my session (some 30-odd I think) were all very friendly and eager to listen – I couldn’t have asked for a better group!

In the top 3? No way!

In fact, I think they were so nice they voted me in to the Top 3 “Speakers by Knowledge of Subject” and “Speakers by Presentation Skills” – accolades that I will soon be transferring onto a tattoo on my forehead, such is the level of my humility (and astonishment!) at appearing here with these two other fantastic speakers. Maybe it had something to do with the fact I was lobbing ‘Telerik Ninjas’ – stress toys – at anyone who asked a question (as a reward, folks – not as punishment)…

By Knowledge of Subject

  1. Steve Sanderson and Getting Started in ASP.NET MVC - 8.88 out of 10
  2. Richard Campbell and Why Web Performance Matters - 8.85 out of 10
  3. Richard Parker (that’s me!) and Getting Started in The .NET Framework - 8.56 out of 10
By Presentation Skills
  1. Richard Campbell – 8.73 out of 10
  2. Richard Parker – 8.33 out of 10
  3. Steve Sanderson – 8.30 out of 10

Looking for the slides?

If you attended and are looking for a copy of the presentation, you can download it below. Well, it’s actually a PDF – handier if you want to stick it on your Kindle, for example.

Getting started with .NET (PDF, 2.4MB)

Find out when your next DDD event is

If you’ve never been to a DDD event, then stop whatever it is you’re doing right now (well, after you’ve finished reading this post, of course) and go figure out when the next one is. They’re all over the place now – even Australia! It won’t cost you a penny to go as the events are all supported by sponsorship, so you’ve really got no excuse to go. The speakers are excellent (yes, even at the events I don’t speak at) and you’ll get a chance to mingle with some very friendly and amazing folks.

I’ve attended these events in the past as a delegate and have always had an absolutely brilliant time. And, this time around I was fortunate enough to be able to attend as a speaker; an experience I enjoyed thoroughly and would love to repeat again (if they, and you, Dear Reader) will have me again …

The .NET community, put simply, rocks. You guys are awesome!

I’ve spoken with a lot of developers recently who haven’t yet adopted the Windows Azure platform, often because they think the process is difficult, time-consuming or requires some kind of advanced ninja training to get up and running.

This video will show you that it can be done in 90 seconds or less, without writing a single line of code!

In the screen cast, I’ll show you how to create a new Azure project in Visual Studio 2010, add a web role to the project, create a deployment package, upload it to the cloud, and then view it running in the cloud.

Before you begin though, head over to the Windows Azure site, and make sure you’ve activated a Windows Azure subscription. If you’re an MSDN or BizSpark subscriber, you get a free basic subscription anyway which is great for this demo. If you’re not, don’t worry, because until June 30th, Microsoft are giving you a free trial, too. Just get started at http://www.microsoft.com/windowsazure/free-trial/.

It’s seriously easy to do, so what are you waiting for – get going! :)


EDIT 30/03/2011:
In this video, I’ve shortened the “deployment” sequence to fit within the timeframe, but it should be noted it is normal for this part of the process to take anywhere between 15-30 minutes (while the Azure platform does what it does to spin up the resources it needs to run your solution). Thanks to all the watchers who pointed out that this fact was probably worth mentioning! :)

As always, feedback is appreciated and welcome.

I gave a talk at Microsoft BizSparkCamp in London on March 25th, and I thought I’d follow that up with a blog post summarising some of the main benefits of deploying your next solution on Windows Azure. These reasons all form part of what I call the “Lure of Azure”.

So here’s a taste of eight of the reasons I broadly covered in the talk:

Reason #1: Financial
Building, deploying and maintaining a Windows Azure solution is likely to cost you far less than acquiring and maintaining your own physical infrastructure. If high availability and redundancy are important to you, I can pretty much guarantee you can’t do it cheaper or quicker than with the Azure platform.

Reason #2: Forget hardware
Very few applications actually need to be run on dedicated physical hardware (“Co-location” etc). Windows Azure abstracts away all the hardware and gives you a platform upon which you deploy code only, and through configuration files, you can determine how much or how little of the resources will be available to your application. Let Windows Azure take away the strain of worrying about load-balancing and redundancy, as all that’s taken care of for you.

Reason #3: Consolidation
The Windows Azure platform allows you to consolidate all your logical services under one account, with one control panel. That means you can instantly provision SQL Azure databases, and make use of infinitely scalable storage resources on-demand from a single point of administration, quickly and easily. Managing Windows Azure applications that utilise SQL Azure, Windows Azure storage and Compute is orders of magnitude easier than maintaining the equivalent physical infrastructure yourself.

Reason #4: Scale up (and down)
If you’re going to buy a physical infrastructure, chances are you’ll over-specify and end up with a lot of spare capacity because you build-in a lot of what you don’t need all the time… I.E. you build to accommodate ‘peak’. That means you’d be paying for what you don’t need (or use) most of the time with any physical infrastructure. Windows Azure solutions can be scaled-up and down on demand, meaning you only ever pay for capacity when you need it.

Reason #5: Build flexibility
If you build on physical infrastructure, when you need more of something (or less, for that matter), you end up messing about with hardware. If you lease (as many of us do), then that means contract variations, change requests, maintenance periods and perhaps even down-time but generally always cost. The Windows Azure platform lets you do all this stuff on-demand, with ease.

Reason #6: Better global reach
Locating a physical data centre in one territory is one thing, but if you want truly global scale it pays to geographically distribute your resources to other territories as well. Co-location is an expensive way to do this, and then you have to think about how you’re going to replicate your data between all your data centres yourselves and the bottom line is: that’s tricky to say the least. Locating resources globally in Windows Azure is as easy as point-and-click.

Reason #7: If you’re a .NET house already, it’s even easier
Using Visual Studio 2010? Know C#? Most of your existing code can run in the cloud immediately with just a few minor tweaks. Go download the SDK and start today.

Reason #8: Flexibility to utilise all, or a part of the platform
Fed-up maintaining your own SQL database cluster? Running out of resources locally? Hosting company charging you too much for a SQL server database? Bung your database on SQL Azure and leave your app where it is. You can use the SQL Azure Migration Wizard to move your databases over to the cloud, then it’s just a simple matter of changing your connection strings in your code. Show me a simpler way of creating a triple-redundant SQL server instance!

There are many other reasons, of course, and I could expand on any of these along the way but the point of this post was to just get you thinking about some of the key advantages by summarising some of the points I discussed in my talk. Feel free to post comments!

Follow

Get every new post delivered to your Inbox.

Join 261 other followers