Sunday 14 October 2012

Exploiting filtering for SQL replication

I came across a novel way of making use of SQL Servers replication the other day.  It erked me so much I thought I would share it with the rest of my casual readers to see what they think about it.  I may just be too much of a purist but the way it was implemented went against everything I've learnt as a computer scientist.

Replication Filters


For those that are unfamiliar with replication, the idea is to propegate data from a central database down to subscribers.  In terms of a business model, this might be head office as the replication publisher and the branches are the subscribers.

For each block of data that needs to get replicated, you can apply a filter as not all data may be relevant to the subscribers.  This would normally be in the form of a Flag for one of the columns, or where the date is within the last x days etc.  The options are only limited by the design of ones database, or in this case, the person's imagination.

The filter applied was:
SELECT <published_columns> FROM [dbo].[Branch] WHERE Code = HOST_NAME()

*HOST_NAME() usually returns the machine name that the script is running on
 

Publisher and Subcriber


The normal process is for the Publisher to Push the data, or the subcriber to pull the data.  Either is pefectly valid, it just depends where you want the processing load to lie.  If you have a lot of subscribers it would be considered  best practise to focus the load on the subscribers so therefore it would be a pull subscription.

When the subscriber runs , it issues a command to SQL server to synchronise the data.  There are various switches and options that can be applied to this command.  One of them is [Hostname].  In this particular instance they have specified a different hostname depending on which branch the subscription is run on.  Therefore the Hostname matches up with the Code column of table Branch.

replmerg.exe" -Publisher [EPOSTEST] -PublisherDB [POSCentral] -Publication [Merge_POSCentral] -Subscriber [eckpostest2] -SubscriberDB [POSPEN] -SubscriptionType 1 -SubscriberSecurityMode 1 -Distributor [EPOSTEST] -HOSTNAME [PEN] -QueryTimeout 300 -LoginTimeOut 30


Aside from the fact this is not how the [Hostname] flag was intended to be used it masks what is truely happening.  When SQL scripts run the hostname and other windows data is used to audit who ran the script on which machine and at what time.  To someone who is unfamiliar with this logic in the replication may end up searching for a machine on the domain that doesn't exist.

What's more is this functionality is not guaranteed to work with future versions of SQL server because the hostname flag is a minor option of replication.

Friday 12 October 2012

The Art Of Wiki Writing

Having introduced an internal wiki to a company and it instantly being a hit, the role of application support has come on leaps and bounds.  However some people are yet to embrace the creation of such pages, or are going about it in a sub optimal manner.

These are some common misconceptions about the wiki that I'm sure will come up again in the future, (cementing my views about point 1).

1) Why do I need to write that down, I know how to do it now?
Yes you do, but will you remember in 3 months time? especially if it's a less common occurance. Also the wiki is not just for you, it's for everyone.


2) I don't want anyone to change my posts, what if they fill it with false information?
Perhaps you should work on your control issues?  Also there is a history you can revert the pages to, so if a page does become "corrupted" you can restore it to a known good page.  Remember, things change all the time and this includes instructions that you've written on wiki pages.

3) I got this error message, I'll just take a screen shot and post it on the wiki, job done.
That's great, but when someone sees an error the message they are likely going to want to search for that error message on the wiki.  In a perfect world it would be able to search the image for text, but until that point comes, it might be a good idea to write out the error message in plain text to accompany the screen shot.


4) I can't show the text as I intended because it has special characters in it.
With any markup language there are escape characters to be used, or escape tags.  Nearly all wiki's will have a page dedicated to the usage/formatting of the wiki.  It should simply be a case of surrounding your text  with the escape characters so your post can be shown as intended.




Tuesday 2 October 2012

The Little Differences

Having spent one month in Australia now, I've had a good chance to see how the little differences between the UK and Australia can make all the difference  (well NSW, and Sydney specifically).  I'm not suggesting either one is better than the other, merely observations that can make a big difference in your daily life.


Pennies: 

Firstly, there aren't any.  The smallest denomination is a five cent coin.  However Prices are still advertised at $1.99 so how does that work?  Well, rounding.  When you get your receipt they will round it to the nearest five cents.  Sometimes you gain, sometimes you lose.


Bed frames:

Now I found this one out the hard way when I ordered my bed, and it wouldn't fit up the stairs.  In the UK if you order a base with the mattress, the base will be split.  In Australia you have to ask for one like that specifically apparently.  Plus it's more expensive because it's not the norm.


Zebra Crossings:

Now this appears to be 50/50 amongst motorists but don't be surprised if they'll completely ignore the fact they are approaching a Zebra Crossing.  If you step out in front of them, they'll do their best to stop (screeching and handbrake incl) , but half of the motorists don't expect to have to stop when approaching one and they certainly won't stop unless your foot is on the tarmac.


Pelican Crossings:

I guess I just got used to the fact that when the green man is on, it's safe to cross.  In Australia, all it means is as a pedestrian you have right of way.  Cars will still be coming at you from any which angle and one has to be trusting that they are aware that people might be crossing.


Vernacular:

This one goes without saying, but you can get yourself into a lot of bother by using the following words in the wrong context.  Thong, Router, Scuba Diver.  Tread carefully as they say.


Paying By Card:

In the UK, it's very simple; you have a debit card for your current account and maybe a credit card that may or may not be issued by your bank.  When you put your card in the machine you enter your pin and that's about the only interaction you have with the terminal.  In Australia, the first thing you must do it select what account type it is, credit, savings or cheque?  WTF why doesn't the terminal know that from the card I've put in?  Plus your Pin number doesn't have to be 4 digits.  So I've gone for a nice lengthy 12 digit one just to confuse the cashier.  Plus it plays a nice tune if you get the tempo right (Think A Team).