Saturday, 14 August 2010

Storing hierarchical data in a relational database

I've seen a fair share of databases, and every now and then you want to store a hierarchy of data. If you want to be able to store a hierarchy of an unknown depth i.e. a family tree, this can be simple to store, but complex to then query. Now I thought the only solution (in a Relational DB), is something called the Adjacency List Model where you have a self-referencing table, for example a Person table, where a person may have a foreign key to Father and Mother, both of whom are also in the Person table. The awkward thing with this, is that to properly query to an unknown depth you need to be able to write Recursive Queries, and not all databases support this. Additionally the queries are a bit complex and do not perform well.

While trying to find out if Access supports recursive queries (which it doesn't without using VBA to do the recursion), I found out about the Nested Set Model. This an alternative to the Adjacency List Model, and something I found very interesting.

Read Mike Hillyer's article for full details on both the Adjacency List, and Nested Set models.
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

Tuesday, 22 June 2010

Autologon

I thought I'd do a quick post singing the praises of another tool from SysInternals called Autologon.

This is a clever little tool where you can feed in your logon name and password, and then when powered on, it automatically provides these and brings you straight to your desktop. Maybe combine that with starting your e-mail client on startup and you can get ready to go just from pressing the power button. Note that the password is encrypted, so you need not fear it's sitting in the clear in the registry.

DISCLAIMER: I am not recommending this be used in any situations. Username and password logons are there for a reason and you should only use the tool if you fully understand the implications involved and do so at your own risk.


That being said the following two cases seem like ones that may be suitable.

  1. You have some sort of full disk encryption in place (i.e. BeCrypt or PGP). You need to supply one set of logon credentials just to get to the OS, so if you're the only one that knows these credentials, the second logon prompt is somewhat redundant
  2. You would rather not have a password prompt on logon, and can guarantee the physical security of the laptop, but can't (or wont) change the machines security settings.

Tuesday, 8 June 2010

Issues with NumericUpDown Databinding

After setting up a form using databinding, I realised that my NumericUpDown controls were not properly updating the underlying object if a value was changed, and the user 'tabbed out', but they would work correctly if the user clicked into and out of the control!

numericUpDown.DataBindings.Add("Value"m_InventoryItems, "UnitCost"TrueDataSourceUpdateMode.OnPropertyChanged)

Thanks to TonyG for sharing the answer.

Friday, 4 June 2010

Programmatically add a Breakpoint with Debugger.Break()

Most of the time when working with visual studio you can debug your applications by simply running your GUI or command-line project in debug mode.

Now sometimes you might be working with projects that are not so easy to debug. For example a windows service, or an installer custom action.

Now one way around this is to create a custom wrapping exe that exercises the same code, but this wont be equivalent to it being run in the field (i.e. from msiexec.exe).

A handy solution to this is to place a call to Debugger.Break() in your code. When this runs windows will ask if you wish to attach a debugger to the running process, which then allows you to debug from this point forward. Great!

Keep in mind you don't want calls to this in your live code! I'd recommend only using it temporarily or ensure it is only included in debug builds by wrapping it in a method attributed with [System.Diagnostics.Conditional("DEBUG")]

Thursday, 3 June 2010

Integrating TortoiseSVN with Bugzilla

My project uses Subversion for version control, and TortoiseSVN as our subversion control client. A very good version control implementation on both fronts.

We also use Bugzilla as our issue tracking tool. The below can also apply to other Issue Trackers, but you will need to do a bit more of the work.

Now I recently found out that you can easily integrate TortoiseSVN with Bugzilla. Linking in this way adds the following benefits:

  • Prompts the user for an Issue reference when committing changes 
  • Records the change against that issue, allowing an indexed search for all changes relating to a given Issue
  • Display the Issue reference in the log message - with a clickable URL directly to that Issue
All of this can be enabled simply by setting the relevant bugtraq SVN properties on the top-level folder. For example I set the properties on the root of my development area, but for a project-wide adoption you can set these properties on trunk.

Here are the bugtraq properties I am currently using:

Simple as that!

Note: We use the term OR (Obersvation Report) in place of Issue in my current project.

Now I can understand those that say this doesn't add a great deal of additional features. Which is true *gasp*. But! It took me 2 minutes to do. For so little effort any benefit is worthwhile, and I definitely think there are benefits.

For more detail on how the available bugtraq properties work, check the official docs. Which are quite clear!

Wednesday, 2 June 2010

Copy and Paste from a MessageBox



Often I find a message box pops up with a message that I want to record, such as an error, and I normally take a screenshot of the active window (Ctrl+Alt+PrntScrn) which is all well and good, and is how I took the above screenshot.

Now I really just want the text and sometimes a picture may not cut the mustard, i.e. entering into an issue trackers 'Description' field, and you don't want to type long messages out by hand.

But I never knew - and I hope I'm not the only one - that if a message box is highlighted, and you use the traditional Ctrl+C keyboard shortcut for copy. It will copy the text to the clipboard. Not just the message, but all text displayed.

For example the above dialog provides the following text extract:

---------------------------
TestTitle
---------------------------
TestMessage
---------------------------
OK  
---------------------------


As you can see you get the Title, the Message (what we want), and the button text. Why it took me this long to find this out I don't know!

Tuesday, 1 June 2010

Remote Desktop Connection - Always use fullscreen

On my OS (XP Professional), the remote desktop client is mstsc.exe, and I always want my remote desktop connections fullscreen. Now it is clever enough to re-use the last session display size, and in most use cases that probably works fine.

My problem is that sometimes I work on my laptop directly, and other times through a docking station. When I switch between them I always find that the remote desktop client has changed the last display size from 'Full screen' to whatever the resolution was in the previous setup - which I have found very annoying!

Today I found my answer. I have the shortcut to this tool in my start menu, and the exe takes a /f switch to indicate fullscreen. So all I needed to do was to change my shortcut to "%SystemRoot%\system32\mstsc.exe /f".

Voila! Whenever I use the shortcut it always defaults to fullscreen! Just the way I like it.

Tuesday, 27 April 2010

Clear text formatting in Microsoft applications

I often find myself copying and pasting. Perhaps from an internal website such as Bugzilla, and when I paste into a word document or e-mail I often find I've brought along some additional text formatting that I didn't want, such as differing fonts and colour.

I used to use Edit->Paste Special->Unformatted Text to avoid this, or if I was in Outlook I might paste it first into the subject box, then copy and paste it into the e-mail.

However, there seems to be a little known keyboard shortcut that can easily strip formatting in most MS applications such as Word and Outlook that does just this job! Ctrl-Space!


As a test, copy the below the paragraph into your nearest app, and try it for yourself.
The quick brown fox
jumps over the lazy dog

Monday, 26 April 2010

Disabling the Windows Command Prompt Beep

I, like most people where I work, have my computer speakers muted. I don't want my PC to make noise and bother other people every time I get an e-mail and the like, and they do the same.

Have you ever been working in the office on the command-line, or run a tool that uses it, hit an error, and suddenly your PC is beeping like you've just poked it in the eye while it's taking a nap? Maybe it's not been you, but you know of other people in your team that start to beep every now and again? Ooo it bugs me! And its twice as embarrassing if it's your own code! :-)

If you don't know what I'm talking about, open a new command prompt, press Ctrl-G, and hit enter.

The problem is that the windows system beep normally comes from the motherboard's own speaker, rather than your 'normal' stereo speakers, and therefore isn't controlled by the system volume.

Luckily there is a very quick and painless solution posted by Gina Trapani. Apply it to your own machine, or send it on to colleagues. My team has been happily without the windows beep for some time!

Copying and pasting on the command prompt (Quick Edit Mode)

Most IT people at some point find themselves opening up a windows command prompt (cmd), and you may also want to Copy and Paste, which you can do. BUT the command prompt's interface for copying and pasting can only be accessed via its rather hidden Edit menu, which can be seen below.












If you knew you could do this, you probably would agree that this is a rather tedious process, and you can't even select the text the way you want to either. Now luckily windows can make this easier for you, but (for some reason!), it doesn't do this by default. If on the above menu, you select properties, you can then enable Quick Edit Mode, as shown.



Quick Edit Mode is much more intuitive and easier to use than the command prompt's default behaviour. Simply use the left mouse button to drag and select text, and then the right mouse button to Copy. From the clipboard you can paste it as normal,  or if you want to paste it back into a command prompt, simply right click!


When saving this change, you can have it only effect your current session, or choose to "Save properties for future windows with the same title".

I like to go one step further, and have Quick Edit mode on by default in any command prompt I open (i.e. VS command prompt), which you can do with a simple registry tweak.

Hope that helps make your time on the command prompt a bit easier!

An error occurred while validating. HRESULT = '80004005'

Visual Studio Setup projects are not great, and I personally have a number of issues with them - but, they do have their uses, and are a common tool in many .NET solutions.

Today I encountered the above error message while building my new Setup project. Now a quick google gives many answer to address this problem, but the gist of it is that your installer contains a Primary Output from another project, that has a Project Reference to one or more other projects. One of these projects being referenced is missing something, for example a file listed in the project is not located on your local disk, or one of the project references is no longer included in the solution.

However, in my case none of the answers I found helped. Then a colleague suggested cleaning the solution, and restarting VS - and that worked!

So I don't know what was the problem in my case, but if you've tried the common solutions you can find via Google and they haven't worked for you, you may as well try a clean and a restart!

Good luck!

Monday, 19 April 2010

Tool: String Functions Online

While getting SyntaxHighlighter to work I saw a reference to a handy online utility to encode text into valid HTML. Saves having to do it manually, or push it through your favourite API!

Nosey fellow I am, I looked around the www.string-functions.com website and saw that it has a number of other useful functions such as URL encode/decode.

Worth a bookmark in my book!

Tool: SyntaxHighlighter on Blogger

Now we're getting serious. I'm looking to post some code on my blog, and as many have found before, just pasting your code in as bland text is just boring, it just doesn't feel like real code until its been parsed into pretty colours that start to give it some structure. (and yes, I am British, and I will stick to correct English "colour", even if CSS doesn't like it!)

So, not one to reinvent the wheel I did some surfing, and came across SyntaxHighlighter, and from there some wonderful, Blogger specific, and up to date instructions!

I had a failed attempt with an older version of SyntaxHighlighter not working with Google Chrome (my browser of choice), but the above was clear and concise, and uses the current version.

So now, to prove it works!

C#


XML


So there we have it! Thanks to Alex Gorbatchev and Shalabhsneha Katdare

Sunday, 18 April 2010

Behind the scenes of PsExec

PsExec is a free tool, available from sysinternals, that allows you to run an executable on a remote machine, in the remote machine's local context. This is a great tool and has many potential uses, and for those of you unfamiliar with sysinternals, it's worth having a look at the other tools they offer such as Process Monitor.

One of the systems I work with had 2 components on a server that interfaced via an executable, and due to that dependency had to be on the same server. Then, on a quiet Friday afternoon a week before the software is demonstrated on the Live hardware, I receive a call basically asking me to separate the dependency so they can be installed on separate servers, and create a new release by the end of the day(!). Now I thought, I can't properly create another WCF web service, and get it tested, in such a short time. I was however familiar with PsExec - but - I did not know how it actually worked, and whether or not it would work in our target environment, which is quite security concious.

As PsExec is not an officially supported tool, there is no detailed documentation, and the best detailed account from the author is only viewable at a cost.

The best explanation I found for how PsExec actually works can be found here

But in summary, I found that PsExec has the following pre-requisites:
  • The user on the source system, must be in the local administrators group on the remote system (that's the doozie)
  • The \\remotesystem\ADMIN$ share must be available
  • File sharing must be allowed between the two systems
  • Ports 445 and 139 must be open
The requirement on the administrators group is the biggest issue, and one that I feel makes PsExec unsuitable in secure environments.

Don't I get a birthday?

Anyone working in IT development knows the problems we can get with the intricacies of working with Dates and Times. One of those issues are Leap Year's, which I'm assuming everyone is somewhat familar with. Although how many of you think 2100 is a leap year? ;)

Now I am one of those unfortunate souls (insert violin), born on a leap year, on the 29th February. This means that 3 years out of four, I don't get a real birthday, but have to celebrate my birthday on the 28th February, or 1st March. As well as being slightly awkward in a social sense, this can also be a problem when working with computers.

Nowadays this is something that is handled very well by 99% of the computer systems out there, and so I'd like to thank the industry for making allowances for the awkward bunch we are.

However, these is still that 1% that treat us differently, and I was surprised to find that Blogger was one of them!

I wanted to enter my DOB on my profile, but hide my age (I'm shy like that), which Blogger says I may do by omitting the year. Great! However, upon entering 29/02, and attempting to save, I am then told "Invalid date". Lies!!

Therefore blogger have denied me the feature to include my correct DOB, without the year. So for those of you that did view my profile, my birthday is 29/02, and not 28/02 as you may have seen.

Gripe over, thank you for your patience!

Introducing

Welcome to the first post, in my first blog!

I'm starting this blog to share the issues I face and hopefully overcome, while working in the IT industry, or in my personal computer endeavours.

I'm hoping that over time I will keep posting with the things I have found really useful and this will become a good resource for myself, and others of you in the IT community.