Archive

Software Development

I ran across an interesting problem today, and I thought I’d blog about it as it may save you some time if you encounter a similar issue in the future.

Scenario: you’ve deployed Visual Studio 2012 Update 1 Remote Debugging Tools to your Surface RT device, and running Visual Studio 2012 Update 1 on your desktop PC (x64, in my case). When you attempt to remote debug on Surface, Visual Studio 2012 reports that it cannot connect to MSVSMON.exe on the remote device.

Background: for testing purposes, I disabled the firewalls on both the Surface and the desktop PC, and I tried configuring MSVSMON.exe to work with and without authentication on port 4016. Visual Studio 2012 Update 1 could never discover the Surface, either, unless I ran MSVSMON.exe as a service on the Surface. As a service, my developer machine could discover the Surface but even then, still couldn’t connect.

For reference, the developer machine was connected via ethernet, and the Surface (obviously) via WiFi to the same router.

Ping from the desktop to Surface failed, but it did resolve the IP address. Ping from the Surface back to the desktop always worked, returning an IPv4 address.

After trying many things for several hours, I tried changing my router because I believed what I was seeing was symptomatic of a networking issue. This immediately cured the problem.

It would seem, at least in my case, that my BT HomeHub 3.0 prevented establishing a connection to MSVSMON.exe between LAN and WiFi. I don’t know why – I can only assume perhaps there is a firmware issue on the HomeHub 3.0.

I can’t verify it with another HomeHub as I don’t have access to a replacement router, however swapping it out for a brand new Netgear DGND3700 did the trick nicely. If you have a HomeHub 3.0 and are on BT Infinity, please let me know if you can reproduce this issue.

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
};
//Start the process
_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:

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

//Attach handlers
_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:

//Start process
_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:

string file=Path.Combine(UnpackPath,"SQLEXPRWT_x64_ENU.exe");
string args=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.

Follow

Get every new post delivered to your Inbox.

Join 357 other followers