Category Archives: microsoft

how to safely run destructive sql statements

christmas afternoon

This tip is one of those “Why didn’t I think of that before” things when I saw it being used first. You see, sometimes you’re on this production database and you need to run some SQL statements in Microsoft SQL Management Studio. Statements that if you mess them up will end up ruining your customer’s day, and most certainly yours too.
Of course you’ve already taken a backup, but that isn’t perfect. It takes time to restore those and the most recent changes might be lost. The database might also be humongous, making backup & restore operations rather annoying.



You know this! Before you run any statement doing anything destructive on your database, first run the BEGIN TRANSACTION statement. It feels like spring doesn’t it? With fluffy little bunnies hopping around merrily in the green grass and yellow flowers.
Whatever you run next, nothing will actually happen until you run:


If in the meanwhile however that delete statement turns out to act like the Spanish Flue and wipes out half of the precious records stored in your database table, there’s always:


Undo. Restore from last save. You don’t lose a life.
Awesome. More fluffy bunnies.

One thing to keep in mind though. As long as your transaction isn’t committed your statements will be putting locks on rows and perhaps even tables. The longer you keep those, the more chance other people’s queries will have to wait for you to release those locks and might even time out. This is bad. So keep your transaction trickery as short as possible.

For more details on those magical statements, see MSDN.

WCF service throws an msmqBinding error on a http binding


So you have this WCF service with a typical HTTP binding on it. When you try to use it with a client, or when you simply open up the .svc file link in your browser, it throws an error message telling you your MSMQ binding is incorrect. MSMQ!

Contract requires TwoWay (either request-reply or duplex), but Binding ‘NetMsmqBinding’ doesn’t support it or isn’t configured properly to support it.

But it’s a HTTP binding! Of course it’s two-way!

It took me a while to figure out what was happening, but apparently it was all caused due to a typo in the binding configuration for the service in the web.config.
So when you run into this, check your web.config binding configuration for that service. An incorrect class path or class name in the service’s name attribute can be causing this effect. Also check for mismatches between the used class in the binding and the class used in the service’s .svc file.

I’m guessing the “missing binding” is causing WCF or WAS (which is installed) to try and activate the MSMQ protocol as a default oslt. I don’t get it really. So if someone reads this and understands why this misleading error occurs, feel free to enlighten me.

Photo by greg biché, cc-licensed.

install multiple windows applications at once


Getting a new computer is awesome. Installing all your most frequently used and essential bits of Windows software on it isn’t. So I searched the web for something that could do this boring task for me. Computers are usually good at that. I remember using something called AppSnap in the past, but that hasn’t been updated since 2008 which makes it so 2008 that I didn’t think of using it anymore. A few well placed Google queries later I ended up with something called Ninite.

Ninite gives you a list of well-chosen and good free and open source software (I’m just saying this cause most of my personal favs are in the list), check some boxes and download a lightweight installer. After that, the installer gets the list of your preselected software and goes off to download them one by one and installs them for you. Like a nice little helper robot monkey oslt. Awesome.
Saved me a bunch of time, which I used to write this little review. Ain’t that something!

Photo by Robert S. Donovan, cc-licensed.

visual studio 2010 becomes slow after saving on Windows 7

Rust and oil inside "Niles machine tool" (HDR)

Ran into this annoying bugger of a problem with Visual Studio 2010 on Windows 7 where every time I saved a file (any file, no matter how large or small it was) the GUI started reacting extremely slow on me. Menu’s didn’t react, keystrokes didn’t appear, scrolling didn’t work. It acted like a whole bunch of stuff was going on, but nothing really was. After a few minutes or so responses where back to normal, until I saved a file again…

While it was happening CPU usage of devenv.exe was fine (very low). Cleaning the solution didn’t help either, which in some cases fixes odd VS behaviour. In short, I was at a loss. Googling for a solution didn’t really bring up a solid answer, until I found a post that mentioned something about jumplists in Windows 7 and VS 2010 being slow. In that post the antivirus software is blamed but that was not the issue in my case, since the issue only started occurring recently without any changes to my setup.

Using the Systems Internals (great tools there btw if you want to dig deeper into your Windows system) file monitoring tool I noticed that a file in a specific path was sort of hanging things. When I looked up the file it did point to those so-called jumplist thingies again. After clearing these shortcut files, VS started acting like normal again.

So, if you’re having issues with a slow VS 2010 on Windows 7 on saving, try clearing the jumplists like this:

  1. Right-click the Start button
  2. Choose Properties
  3. Uncheck both checkboxes under the Privacy group
  4. Click the Apply button
  5. Re-check both checkboxes
  6. Press OK

If you’re lucky, VS should be running smooth as butter again.

Photo by Morgennebel, cc-licensed.

cleaning up disk space on windows round-up

I installed my PC initially with a separate C drive dedicated for Windows and system specific files. Unfortunately it turned out that I picked that drive too small as I didn’t foresee that there is plenty of software out there that simply won’t allow you to install to a different location than C:\Program Files. To add to that, Windows itself had its share of service packs and updates which doesn’t actually make it smaller in size either. And then there’s the .NET framework, in all it’s versions.

So soon I ran into the very annoying issue that Windows kept telling me I was running low on disk space on my C drive. This eventually causes updates unpacking to your temp folder (also on the C drive of course) to fail, stuffing up even more hard drive space. Over the years I found a few tricks to avoid or fix this issue and as a good blogger I also documented those right here.

Here’s a little round-up of what you can do to free up some disk space, or create some more:

Spread the word if any of these tips helped you out and saved you from wasting hours reinstalling your machine. It saved me from doing just that a few times, so I’m hoping this post can be a huge time-saver for anyone coming across it.

will windows phone 7 cut it?


A few weeks ago I was in the lion’s den at Schiphol watching a presentation of the new to come Microsoft Windows Phone 7. It was supposed to be Windows Phone development thing, but it turned out to be more of a marketing rant than a geeky app development preview. Bummer.

But hey, since we where there, we might as well get a glance of that sexy (or so they want us to believe) new phone the MS guys came up with right? Well, apparently the phone’s hardware is going to be almost completely fixed. No matter what brand you’re getting the GPU, CPU, amount of RAM, OLED display (including resolution) and Windows buttons (like the Android buttons) are fixed. If it doesn’t that the specs set my MS, it’s not going to be a WinPhone. Manufactures do get to play with the design, a potential hardware keyboard and the on board camera which has to be at least 5 mega pixels. Apparently that’s what the manufacturers want. When it comes to competing it’ll be all about making a pretty phone then I guess.

That the hardware is fixed also makes it easier to to maintain the OS and the device drivers. Both of these will be in the hands of the Redmond lads which is interesting. Microsoft will be the one to blame when the phone doesn’t work as expected and not Motorola, HTC, Samsung or whoever built the damn thing. This could be a good thing for quality and could avoid issues like on Android phones where one brand of phone gets it’s OS updates a lot faster than the other.

When it comes to the OS features it’s what you expect and know of the competing phones. It has a native IE, searches using Bing and integrates as expected with a bunch of online Microsoft services like Live/Hotmail, XBox Live (if available in your country) and the Zune for music (if available in your country). This sort of makes me think about iTunes lock-in on the iPhone. It was to be expected MS wasn’t going to shy away from some vendor lock-in mechanism’s here and there right. This phone is going to integrate nicely with your Windows Media Player and your Windows 7 or Vista OS of course. Oh yeah and they support Flash. They made sure that was clear.

So what about apps? Well, they are mainly taking the iPhone route there. There’s going to be an app-store and they are going to approve every app published on it. All under the guise of quality assurance they are training a bunch of developers in India to routinely approve each submitted app before it gets unleashed on their phones. In fact, they are going to sign each app with a Microsoft certificate after it’s approved. This means that as an app developer you have to submit your source code as well. Creepy. Releasing apps through the Marketplace  isn’t going to be cheap either. 99$ a year. You then get 5 apps “free” and for each additional app you have to pay an extra 20$. So watch out how you version those apps I’d say. 99$ is the same cost as for access to the the iPhone app store. Google’s Android store is cheaper with only a 25$ to pay.

Developing the apps is done with Visual Studio. You can use the freely downloadable (but crippled) Visual Studio Express editions to develop a WP7 (WordPress 7? No! Windows Phone 7!) app using C# (or any other .NET language I suppose) and a WPF-like XAML for the user interface. For developers working in .NET this will make app development a breeze using their trusty and known toolkit. Integration with a bunch of online Microsoft services to make your apps location aware, do searches using Bing and use apps in the Azure cloud are also available. Interesting to see if these idea’s are going to give this phone the edge it’ll need to drag people away from their Android devices and iPhones.

Personally I’m hooked on Android. Both WP7 and iPhone reek of vendor lock-in to me which is enough to not even consider them. DRM’d Zune downloads and iTunes requirements annoy me, but since not everyone cares about these issues I’m sure there will be adopters for this as well.

If hipsters go for Apple phones and geeks go for Android phones, will mom and pop go for the Windows phones?

Photo by bitzcelt, cc-licensed.

LINQ to SQL performance tip

LINQ to SQL is a pretty cool way to work with data from a relational database when you’re programming with .NET.
One of the big advantages of LINQ is that it makes writing SQL statements a thing of the past. So you don’t have to remember which SQL statement does or doesn’t work on what version of your database. Another great thing  is that LINQ generates your SQL dynamically, depending on what you’re trying to do with it

The trick is that in most cases LINQ is better at writing good SQL statements than you are. Ok, you might be a SQL guru and you might be able to write a kick-ass super-performing query, but a lot of people aren’t. LINQ just knows the  tricks it takes to get your (probably Microsoft) database to do your stuff in the best way possible. At least, that’s the whole idea.

But (and here it comes) in some cases LINQ writes something that makes a wintered DBA cringe in terror as he sees those automatically generated SQL statements fly by in his SQL profiler.

So does LINQ suck because it does this? Are you better of writing your own statements like we did in the past? Hell no! You’d be giving up on a lot of good stuff just because a few SQL statements turned out to be monstrously malformed bastard children from the depths of table-scan!

What you should be doing however is profile the SQL statements your application spews out towards your database and see what they look like. If you see something ugly that you know is going to give you a performance headache someday, it’s time to rewrite that LINQ query into something that makes the SQL queries look better.

One thing I noticed you should be careful about is when you use a groupby statement in your LINQ to SQL code. This doesn’t always result in a GROUP BY clause in SQL as well, as you might expect. What it can turn into is out a loop where all your data is read sequentially and then grouped in memory before it’s returned to your C# code. As long as your data set isn’t too large this won’t be a problem. In case it is, you’re better of not using the groupby. One thing that works is fetching the data as is and group it in code yourself using LINQ to objects once it’s loaded.

Your SQL code might also show a lot of nested selects with the where-clause in the wrong place. This causes a lot of data to be read first and filtered out later. You can see this when you watch the SQL execution plan. What you really want is this filter to kick in as early as possible and not waste all those precious resources loading and processing data you don’t need anyway.
I found you can fix this by splitting up the LINQ statement into separate statements. Make sure your where conditions are in the first one. Then use that LINQ query as the base of your next one and you’ll see that the where-clause in your resulting SQL statements will pop up in the right place.

So basically LINQ is a great way to access your data, and keep your code clean from SQL statements IMO. Just keep in mind you still have to take a peek at that SQL code LINQ generates though. So maybe the tips above can help.