Tim

Footprints in the snow of a warped mind

Thursday, April 19, 2007

Where to find me

Flickr Icon  Twitter Icon  Linked In Icon  FaceBook Icon  Windows Live Alerts Butterfly  RSS 2.0 

The Site Doctor is Hiring!

Enjoy what you read here?
Think you can do better?
Join our team and get paid
up-to £35,000.
Apply now.

Tag Cloud

AJAX (4) Analysis (3) ASP (6) ASP.Net (59) Error Reporting (4) Web Service (2) WSDL (1) Atlas (2) Azure (1) Born In The Barn (1) Business (94) Business Start-up Advice (36) Client (17) Expanding Your Business (24) Recruitment (1) C# (25) Canoeing (4) Canoe Racing (5) Cheshire Ring Race (5) Racing (2) Training (4) Christmas (1) CIMA (1) Cisco (1) 7970G (1) CMS (1) Code Management (1) Cohorts (4) Commerce4Umbraco (1) Content (1) Content Management (1) Content Management System (1) CSS (4) dasBlog (5) DDD (2) DDDSW (1) Design (12) Icons (1) Development (27) Domain Names (1) eCommerce (12) Email (1) Employment (2) Festive Sparkle (1) General (39) Christmas (6) Fun and Games (11) Internet (22) Random (46) RX-8 (8) Git (2) Google (1) Google AdWords (1) Google Analytics (1) Hacking (1) Helpful Script (3) Home Cinema (2) Hosting (2) HTML (3) IIS (11) iPhone (1) JavaScript (5) jQuery (2) LINQPad (1) Marketing (6) Email (1) Multipack (1) MVC (3) Networking (3) Nintendo (1) Nuget (1) OS Commerce (1) Payment (1) Photography (1) PHP (1) Plugin (1) PowerShell (3) Presentation (1) Press Release (1) Productivity (3) Random Thought (1) Script (2) Security (2) SEO (6) Server Maintenance (7) Server Management (12) Social Media (2) Social Networking (3) Experiment (1) Software (11) Office (5) Visual Studio (14) Windows (5) Vista (1) Source Control (2) SQL (11) SQL Server (19) Starting Something New (2) Statistics (2) Stored Procedure (1) Sublime Text 2 (1) SVN (1) TeaCommerce (1) Testing (2) The Cloud (1) The Site Doctor (139) Turnover Challenge (1) Twitter (3) uCommerce (17) Umbraco (36) 2009 (1) 2011 (1) Useful Script (4) Virtual Machine (1) Web Development (72) WebDD (33) Wii (1) Windows Azure (1) XSLT (1)

Blog Archive

Search

<April 2007>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Recent Comments

Blog Archive

Various Links

Google+

Blogs I Read

[Feed] Google Blog
Official Google Webmaster Central Blog
[Feed] Matt Cutts
Gadgets, Google, and SEO
[Feed] Ol' Deano's Blog
My mate Dean's blog on my space, equally as random as mine but not off on as much of a tangent!
[Feed] Sam's Blog
Sam is one of my younger brothers studying Product Design and Manufacture at Loughborough, this is his blog :) Enjoy!

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

newtelligence dasBlog 2.2.8279.16125

Send mail to the author(s) Email Me (Tim Gaunt)

© 2014 Tim Gaunt.

Sign In

# Thursday, April 19, 2007

Getting more work done - Early Mornings vs. Late Nights

Thursday, April 19, 2007 6:25:11 AM (GMT Daylight Time, UTC+01:00)

If you’ve ever been involved with running your own business or indeed any start-up you’ll know long hours are sometimes a necessary evil to meet the demand or even just getting things in order. Well for quite some time now I’ve been wanting to work out whether it’s better to work early in the morning or late at night –I’m quite happy at working either but is there a better option.

Recently I’ve needed to work long hours to get a couple of systems completed and get back on track with a couple of projects so decided there wouldn’t be a better time. I did want to do something clever like monitor the number of lines of code I write or something equally measurable but to be quite honest I didn’t have the time and I couldn’t be bothered to spend hours searching for a solution so it’s all finger in the wind stuff…

Late Nights

Firstly I tried late nights. As I mentioned in my business start-up guide (see: Business start-up advice) I’m very strict with getting up –I get up when Stacey does, see her off and then I’m in the office from around 7:30am/8am (please don’t call then –I like to have a little “quiet time” to sort things out ;)) and I work until she gets home –usually around 7pm now she’s in her new role. When doing the late nights I’d go in at around 7pm, have a drink and a chat, a bite to eat, perhaps all in all an hour or two’s rest before returning to the desk for a couple more hours.

What I found with working into the night was that by the time I got back into the office I was already fairly tired from the day that had preceded (which a lot of the time is unpredictable as far as clients are concerned!) so my productivity for these additional 5/6 hours was lower than during the “normal” working day, then when I got up the next morning I would be pretty shattered from having little sleep (I still had to get up at 6:30am) which meant the next day was somewhat of a write off. So although I managed an additional 5 or 6 hours of lower productivity work, I also lost time the next day so it was semi-even.

Early Mornings

After testing working late for a couple of weeks I decided to try getting up early –initially I would get up at 5:30am as that would give me an hour or so before Stacey was awake, then 10mins waking her/refilling my tea and then another hour or so before breakfast and seeing Stacey off. I tried the 5:30am start a couple of times and could see the productivity difference almost straight away. As I was starting after a good nights rest (I could finish earlier and even get to bed earlier if I wanted!) I was fresh and ready to go again so I decided to start getting up at 5am, that way I could have nearly 4 hours of uninterrupted time before clients started calling.

By getting up at 5am you avoid the jet lagged feeling at the end of the day, oddly enough this still comes at around the same sort of time so you don’t really lose out there and the 4 hours or so before other people make it into the office which means you get an additional 4 hours of uninterrupted time.

The other advantage was if you had a deadline to meet you also had the evening available to work into –again at a fairly similar productivity level to when you get up at 6:30am.

Conclusion

Although I’ve not done any productivity level testing I know for sure that getting up in the mornings is far better without a shadow of a doubt, having the uninterrupted time where you’re fresh and alert means the development is a lot faster, unlike in the evening/night, no-one is online just “chilling” which a lot of the time can be distracting in itself, you’ve also got the added advantage of having a full nights sleep if required or working late into the night if you need to hit a deadline.

Despite my findings I still know a lot of people that stay in the office late into the night thinking that it’s of benefit but one thing I found was not only was your productivity lower, your likelihood in making mistakes was higher –which you’d just have to correct the next day. A lot of the time they were simple things that had you been paying attention/been awake for you’d have sorted!
Another thing I would like to look into at some point is whether morning or afternoon coding is more efficient and whether you can use that to structure your day better as from this “investigation” I’m inclined to do more adminy type work in the afternoon as I tire and leave the development to the morning (that is my 8 hour morning… ;))

FWIW I really enjoy getting up before everyone else, watching the sun rise and then having an evening to go to the gym and have been getting up early now for a fair few weeks –and don’t see it changing anytime soon! I think any earlier than 5am however may well be detrimental.

 

Don't forget to follow me on Twitter.

# Tuesday, April 17, 2007

SQL Server Delete all data

Tuesday, April 17, 2007 4:18:54 PM (GMT Daylight Time, UTC+01:00)

I expect many people already know about this technique but I wanted to share it with those that don’t. The other day I needed to remove all data from a database before importing data from another database. I usually use DTS to copy the data across but knew that the database (one test) had conflicting ids so I decided deleting all the data out of the test database would be the best way to ensure all data’s up to date.

I found this useful little set of SQL at: http://sqljunkies.com/WebLog/roman/archive/2006/03/03/18386.aspx, there are two solutions propsed within the post and comments so here they both are:

Delete the data without resetting the identities

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO

EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO

Delete the data and reset the identities

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 
GO 

EXEC sp_MSForEachTable 'TRUNCATE TABLE ?' 
GO 

-- enable referential integrity again 
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' 
GO
 

Don't forget to follow me on Twitter.

SQL Server Delete all data
Useful Links:  #  digg it!  del.icio.us  Technorati  email it!  Post CommentsComments [7]  Trackback LinkTrackback
CategoriesTags: SQL Server | Web Development
# Wednesday, April 11, 2007

Rackspace -awesome managed dedicated servers

Wednesday, April 11, 2007 12:59:46 PM (GMT Daylight Time, UTC+01:00)

Seeing as I’ve had a number of posts recently that were, well, er slating/pointing out terrible customer service and/or service in general I thought it was about time I posted about the guys that did it right in my eyes (that and a couple of seriously cool programming things I’ve found/done –but those can wait!).

If you read my recent post about Fasthosts and how they’ve been going down hill for the last year or so you’ll already know that we’ve signed up to one of the worlds greatest managed hosting companies ever –Rackspace. Not only that, we also recently became an official Rackspace partner which I’ll come back to in a moment.

We got our first dedicated server with Rackspace nearly two years ago as part of a large project we had in the pipeline, although cost was a large factor in our decision, we took into account other aspects of the service such as how our enquiries were handled, the reputation of the hosting company throughout the development community etc. Rackspace although they were one of the more costly solutions for our requirements came off best all around. Even before we were signed up, Rackspace’s customer service was second to none, they were quite happy to discuss the more technical aspects of our requirements and even worked closely with us to identify the most suitable solution.

One thing that I really liked about Rackspace before we signed up was the fact that they were very open and honest –where the sales person didn’t know the answer, they felt perfectly at ease to say so and pass you over to one of the technical support staff who always knew the answer. From my POV, not having someone “guessing” the answer is incredibly important –even more so when mission critical applications are being put in place.

One thing that was very important to us when signing up was scalability, at the time, the requirement for the server was relatively low (the application was still in the pre-development stages but we knew we had to get a dedicated server in place before it got to the develop stages) so it was a risk that we needed to take but we also needed to limit the risk involved. Rackspace were able to offer the backbone (and supporting evidence) that we were looking for. They were quite happy letting us have a smaller solution to start with which could then easily be upgraded when we needed to –within a maximum of 24 hours notice!

Another key factor was the on-going customer help and support, not having any real-world prior experience in managing a server I was adamant that whoever we hosted our server with had to also be able to offer us the technical support we would no-doubt be needing –not only with getting started but also looking to the future general day-to-day cock-up’s. Rackspace has a motto of “Fanatical support” which although many companies claim similar was clear they really believed in. Unlike many other hosting providers out there Rackspace had dedicated support specialists in the various aspects from Window Servers, Linux/Apache Servers to IMail specialists. This has saved our bacon on many an occasion. Although you may get through to someone who is specialised in another area, if they don’t know the answer you’re put through to the next available support member almost immediately. It certainly beats speaking to some spotty teenager who kinda knows what you mean when you talk about the web but is more interested in the Yankee dollar for a day of picking up the phone and pissing people off.

Since signing up with Rackspace, having our dedicated server managed by Rackspace has been a dream. Like I’ve said, they are expensive but that cost is more than compensated by the complete lack of stress I have when dealing with them, the solution they recommended has met our needs perfectly so I’m pleased we’ve not been spending out unnecessarily. On top of this, Rackspace’s motto of “Fanatical support” is an understatement, their customer service and support is second to none without a shadow of a doubt. I’ve called them at some very odd hours and there has always been a friendly understanding voice at the other end… “that’s ok Tim, we can restore that folder you deleted before your client notices…” ;)

In the two years I’ve been with them I’ve had three issues with the server:

  • A HDD failure –not sure what it was beyond that, IIRC it was just a dodgy disk (manufacturers fault). Rackspace notified me of the issue, replaced the HDD and ensured all the data etc was how it should be in the space of 15minutes! As the RAID setup meant the server continued to be operable while Rackspace were sorting the issue I wouldn’t have known if they hadn’t had called me.
  • Power loss for approximately 1hours. Shortly after our server was moved into a new data centre we lost all connectivity. When we called Rackspace about the issue we were told that a capacitor had blown between the server room and all power supplies. We later found out that they had used a new company to install the equipment and they hadn’t checked it all in as much detail as they perhaps should have done. At the time we only had a couple of sites on the server so I wasn’t too concerned about it but Rackspace refunded something like 10% of the entire month’s hosting bill for the inconvenience.
  • Failed firewall. This only happened the other day but the firewall died for some reason, at first they thought it was the PSU but on replacing that it still wasn’t rectified. All sites were down for about 40minutes while it was being sorted. Not great but unavoidable and at least they sounded genuinely concerned. I was even kept in the loop throughout and knew exactly what was going on –right down to “the tech is running to the storage area now to get the PSU… …now he’s running back” (I don’t think my comment of “Run forest RUUNNN” went down as well as I had hoped!).

On top of those issues Rackspace have also helped us out on countless occasions where we weren’t quite sure if we were going about something the right way or we’d messed something up, I’ve only had to use the restore facility once IIRC but that was simple, within 20mins I had restored around 3GB of files to their state from the night before.

Mainly through sheer laziness and not having a re-useable statistics package on the dedicated server (I don’t need it as we analyse the raw logs) until recently the majority of our web sites remained on a Fasthosts shared server account and seeing as a shared server account has many limitations in regards what you can do with your programming and the terrible customer service we’d been receiving we recently transferred the majority (not all) of our web sites away from Fasthosts onto our shiny Rackspace server.

The transition was so simple and easy it was an absolute pleasure. You manage your DNS settings through their online portal which also has a very detailed and easy-to-use support ticketing system. Once setup in the portal you setup the domain on your server and away you go so I’m one happy bunny. They even helped install (unsupported) software for statistics analysis (without any additional charges) and helped me remove the quotas I had applied to the C: drive by accident. As if that wasn’t enough Rackspace even took the time to talk through some of the finer points of server management with me.

What’s this about being a Rackspace partner? Well, you may think that my judgement is swayed by the fact that we were recently asked to be partners with Rackspace but I really wish I’d written about them before this because they are genuinely a superb company and I don’t want you to think that I’m just saying that for the commission (though that is an added bonus I must admit!). If you want unparalleled customer support and a managed hosting solution that really is there all the time for you then choose Rackspace –I’m yet to fault them (and having seen what it gets me, I can’t fault them on the price as it’s well worth it for the help and support they’ve offered me in the past).

In many ways, Rackspace and the Rackspace support team are very much part of my team, I know they’re always there and unlike other people in my team are always happy to hear from me (at the start of the call at least!).

Rackspace, Rackspace, Rackspace, oh how I love ye! If you’re thinking about setting up a server with Rackspace let me know and I’ll put you in contact with people that can help I definitely recommend Rackspace as your hosting partner even if it's just for an easier life :)

Oh, and if all this wasn’t enough –they even send you a bunch of freebies for being a customer and a 12month congratulations certificate! –Cheesy I know but it’s the thought that counts! –and I use the free 256MB key they sent me as part of becoming a partner to store my blog posts on the go now* so thanks for that. Note to any supply company -I (and I think anyone else out there) LOVES free stuff so send it over... ;)

*Yes I know I could have got several hundred 1GB disk keys for the price I pay on hosting but then I wouldn’t get to talk to the lovely support staff ;)

 

Don't forget to follow me on Twitter.

# Friday, March 30, 2007

Discounts on organic aromatherapy products including essential oils and more

Friday, March 30, 2007 2:05:09 PM (GMT Daylight Time, UTC+01:00)

I don't want to be seen to be using my blog as another way of pimping out my client's services to my lovely readers -I'm really not, it's just that I've been so busy recently I've not had a chance to finalize some of the content that I'm going to upload shortly. In the mean time though, if you're into aromatherapy -or more to the point organic aromatherapy check out Florame organic aromatherapy's special offers on all sorts of great items.

Here's the email (there's no need to use a special offer code with this one)

Hello and thank you for signing up to receive our newsletters which are designed to inform you of new and exciting changes at Florame - including our first ever sale - our Spring Sale

Our Spring Sale begins today (Friday 30 March 2007). There are over 30 organic items on sale with discounts ranging from 25% to 50% including:

However stocks are very limited and once they're gone, they're gone! 

View all the items in our Spring Sale here

Don't forget, if you've got loyalty points you can use these to buy your bargains and remember you'll collect more points for every purchase you make. 

All orders over £30 (exc VAT) receive free shipping. 

All orders made before noon will be shipped the same day (except weekends, when they'll be shipped the following Monday).

We hope to welcome you to www.florame.co.uk soon and happy bargain hunting!  

 

Don't forget to follow me on Twitter.

# Friday, March 23, 2007

Threshers do it again -another 40% discount voucher! This time for Easter

Friday, March 23, 2007 12:00:23 PM (GMT Standard Time, UTC+00:00)

As you're probably aware, at Christmas the Threshers Group put out a 40% discount voucher for the Threshers Group, well it would appear they’ve decided to do it again so I thought I should share it again, as before, the Threshers Group 40% Easter discount voucher can has a couple of T&Cs including no Champagne, Sparkling or Fortified Wine, other than that, it doesn’t appear to have the same £500 limit as before so drink up guys and girls!

Download the 40% Easter discount voucher for the Threshers Group

The voucher is valid until 1st April 2007

Remember: If you're looking for some naughty fun this Easter, check out the Miss Mays Adult Store for all sorts of adult toys and games

 

Don't forget to follow me on Twitter.

# Wednesday, March 21, 2007

Simple accounting database

Wednesday, March 21, 2007 8:27:16 AM (GMT Standard Time, UTC+00:00)

As part of my mini-series on Business start-up advice I posted a simple accounting database (see: Finances (VAT, Accountants etc)) but today I realised I had just uploaded the mdb which won't be served by IIS so I just wanted to let you know I've uploaded it as a zip (incase you were one of the people that tried to download it).

Example Microsoft Access Accounting Database (21KB)

 

Don't forget to follow me on Twitter.

# Monday, March 19, 2007

How to use Phil's error reporting code

Monday, March 19, 2007 7:34:20 PM (GMT Standard Time, UTC+00:00)

I’ve done a number of posts now on Phil Whinstanley’s error reporting class and this blog appears to be getting a lot of hits because of that which is pretty neat, as a result I’ve had a couple of people write to me asking similar questions about the code so I thought it would be an idea to write a little summary.

Where can I download the code?

It would appear that most of the old copies of Phil’s code have disappeared from the web, I’m not sure why so I’ve uploaded the versions I’ve got below. For convenience I have compiled the code into DLLs for those that don’t know/want to do this and I’ve also included the Visual Studio solutions. I’m not sure if these are based on the original codebase but I don’t think I’ve made any major alterations to these versions:

1 This is a version I was sent as his original including changes and example email was lost...

DLLs only:

If you have Visual Studio:

If you don’t have Visual Studio you can either download one of the above projects and delete the solution/project files or download the original WebException code. Ok, now you have the files :) -FWIW I can accept no responsibility for any of the files or the code, I just zipped them!

How to do I use the WebException class?

I’m now using a slightly modified version of the code to enable error reporting within AJAX (see: Reporting errors from AJAX using the WebException Class) which I’ll try and upload later but whichever version of the code you choose the use is pretty much the same.

Once you have referenced the DLL in your project (see: Importing/Referencing DLLs in Visual Studio) you will be able to use the WebException. As I’ve covered what you need to do to use the code from within an AJAX application in another post (see: Reporting errors from AJAX using the WebException Class) I’ll just cover how to use it to report global errors. To capture and respond to all application errors you will need to place this code within the global.asax, your project should automatically have one, if it doesn’t then you will need to add one.

Using the global.asax file, the first thing you need to do is add a reference to the DLL at the top of your code (this will allow you to call the methods and access the properties):

<%@ Import Namespace="ErrorReporting" %>

Next locate the Application_Error event handler, this is the method that handles all errors within the application (with exception of those thrown from within an AJAX application, read this post to report errors from within an AJAX application). Now replace your Application_Error and Application_PreRequestHandlerExecute handlers with (for more information on what I'm doing here see: ASP.Net WebException and Error Reporting useful code):

void Application_Error(object sender, EventArgs e)
{
    bool reportErrors = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["SendErrors"]);

    if (reportErrors)
    {
        Exception currentError = Server.GetLastError();

        #region Deal with 404's

        //Redirect the user to a friendly page
        if(CheckForErrorType(currentError, "FileNotFound"))
            RedirectToFriendlyUrl("");

        #endregion
        #region Deal with Spambots

        if (CheckForErrorType(currentError, "System.FormatException"))
        {
            if (HttpContext.Current.Request.Form.Count > 0)
            {
                foreach (string key in HttpContext.Current.Request.Form)
                {
                    if (key.IndexOf("_VIEWSTATE") > 0 && HttpContext.Current.Request.Form[key].ToString().IndexOf("Content-Type") > 0)
                        return;
                }
            }
        }

        #endregion

        //Enable the trace for the duration of the error handling
        TraceContext t = HttpContext.Current.Trace;
        bool bCurrentState = t.IsEnabled;
        t.IsEnabled = true;

        #region Handle the Exception

        ErrorHandling.WebException WE = new ErrorHandling.WebException();
        WE.CurrentException = Server.GetLastError();
        WE.MailFrom = "you@yourdomain.com";
        WE.MailTo = "you@yourdomain.com";
        WE.MailAdmin = "you@yourdomain.com";
        WE.Site = "Your Site's Name or URL";
        WE.SmtpServer = "localhost";
        WE.FloodCount = 10;
        WE.FloodMins = 5;

        #endregion
        #region Choose what you're interested in

        WE.ReturnCache = true;
        WE.DrillDownInCache = true;
        WE.IncludeApplication = true;
        WE.IncludeBrowser = true;
        WE.IncludeEnvironmentVariables = true;
        WE.IncludeForm = true;
        WE.IncludeProcess = true;
        WE.IncludeQueryString = true;
        WE.IncludeRequestCookies = true;
        WE.IncludeRequestHeader = true;
        WE.IncludeResponseCookies = true;
        WE.IncludeServerVariables = true;
        WE.IncludeSession = true;
        WE.IncludeTrace = true;
        WE.IncludeVersions = true;
        WE.IncludeAuthentication = true;

        #endregion

        WE.Handle();

        //Return the trace to its original state
        t.IsEnabled = bCurrentState;

        //Redirect the user to a friendly page
        RedirectToFriendlyUrl("");
    }
}

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
    if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
        ErrorReporting.SessionTracker.AddRequest("Pre Request Handler Execute"truetruefalse);
}

private bool CheckForErrorType(Exception ex, string errorText)
{
    if (ex != null)
    {
        //Check the exception
        if (ex.GetType().ToString().IndexOf(errorText) > 0)
            return true;
        else
            return CheckForErrorType(ex.InnerException, errorText);
    }
    else
    {
        return false;
    }
}

private void RedirectToFriendlyUrl(string Url)
{
    if (!String.IsNullOrEmpty(Url) && (Request.Url.Host.IndexOf("localhost") < 0))
        Response.Redirect(Url);
}

This will create a new instance of the WebException object, assign the various properties accordingly (you will need to configure these) and then finally handle the error.

That’s it! That’s all you really need to do to have super error reporting instantly installed in your application! If that wasn't enough it's overloaded with a couple of filters for you :). I recommend you read one of my previous posts I’ve added which overviews a few simple tips and tricks when using the WebException class to that improves on its functionality (see: ASP.Net WebException and Error Reporting useful code).

All that's left to do is to test it works (see below).

What should I get from it?

That’s the million dollar question! Once the WebException class has been added to your application you should receive an email every time the application throws an error (which of course means you’ll never get an email from the system!)

View an example of the email you’ll get with all outputs set to true.

More tips/Warnings!

Ok so it’s installed and you’re getting no errors through (because your codes perfect) but there are a couple of other little tweaks I would make to the WebException class to make it a little more useable.

Create a centralised class for it

A while ago I posted a set of “useful” tips for reducing the number of spambot related emails, redirecting the user etc (see: ASP.Net WebException and Error Reporting useful code). That’s fine until you start including the WebException class into multiple projects, managing tweaks to the codebase gets a little cumbersome (i.e. adding the spambot check to all our projects that use the WebException meant a couple of hours of copying and pasting). The work around for me was to wrap it all up into a central static method (see: Reporting errors from AJAX using the WebException Class). I did this rather than fiddling with Phil’s WebException class itself incase he ever got around to releasing another version which would mean a bunch of changes etc.

Limit the page request log

If you have a site where every user is likely to have a high page visit count with most of the pages involving some form of form submission then it may be worth limiting the number of request’s stored as we have found that without limiting these we start receiving very large emails (some topping 10MB).

The reason this is happening is because the session tracker logs all the form elements for the request so if you had i.e. a CMS that submits a page of content every other page request all that data will be stored in the tracker, sticking with the idea of a CMS, your typical text word is around 10bytes (see: How many bytes for...), so say the user writes 500 words per page (which isn’t really a lot) that’s 4.9Kb per form submission plus on the re-display of the page you've got ViewState... That’s just the data submitted by the user, around that, you’ve got all the form fields, field names, session info, query string etc, see how it starts to add up?

The solution is fairly straight forward, what you need to do is alter SessionTracker.cs1:

1I thought I'd done this in a project already but cannot find the source so this may not work.

public class SessionTracker
{
    public static void AddRequest(string Comments, bool DoForm, bool DoQueryString, bool DoCookies)
    {
        Request R = new Request();
        R.Time = DateTime.Now;
        R.Comments = Comments;
        
        if (System.Web.HttpContext.Current != null)
        {
            R.Path = System.Web.HttpContext.Current.Request.Path.ToString();
            if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
            {
                R.Referrer = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();
            }
            if (DoForm)
            {
                R.Form = System.Web.HttpContext.Current.Request.Form;
            }
            if (DoQueryString)
            {
                R.QueryString = System.Web.HttpContext.Current.Request.QueryString;
            }
            if (DoCookies)
            {
                R.Cookies = System.Web.HttpContext.Current.Request.Cookies;
            }
        }

        if (System.Web.HttpContext.Current.Session["RequestCollection"] != null)
        {
            RequestCollection RC = ((RequestCollection)System.Web.HttpContext.Current.Session["RequestCollection"]);
            RC.Add(R);
            if(RC.Count > 10)
                RC.RemoveAt(0);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
        else
        {
            RequestCollection RC = new RequestCollection();
            RC.Add(R);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
    }

    public static void AddRequest(string Comments)
    {
        Request R = new Request();
        R.Time = DateTime.Now;
        R.Comments = Comments;
        
        if (System.Web.HttpContext.Current != null)
        {
            R.Path = System.Web.HttpContext.Current.Request.Path.ToString();
            if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
            {
                R.Referrer = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();
            }
            R.Form = System.Web.HttpContext.Current.Request.Form;
            R.QueryString = System.Web.HttpContext.Current.Request.QueryString;
            R.Cookies = System.Web.HttpContext.Current.Request.Cookies;
        }

        if (System.Web.HttpContext.Current.Session["RequestCollection"] != null)
        {
            RequestCollection RC = ((RequestCollection)System.Web.HttpContext.Current.Session["RequestCollection"]);
            RC.Add(R);
            if (RC.Count > 10)
                RC.RemoveAt(0);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
        else
        {
            RequestCollection RC = new RequestCollection();
            RC.Add(R);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
    }

    public static void AddRequest()
    {
        Request R = new Request();
        R.Time = DateTime.Now;
        
        if (System.Web.HttpContext.Current.Session["RequestCollection"] == null)
        {
            RequestCollection RC = ((RequestCollection)System.Web.HttpContext.Current.Session["RequestCollection"]);
            RC.Add(R);
            if (RC.Count > 10)
                RC.RemoveAt(0);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
        else
        {
            RequestCollection RC = new RequestCollection();
            RC.Add(R);
            System.Web.HttpContext.Current.Session["RequestCollection"] = RC;
        }
    }

    public SessionTracker()
    {
    }
}

Outputting the Trace with the WebException Class

I know this is something I’ve posted about in the past but since moving to version 4 of the code and .Net 2.0 I was no longer getting the trace in my lovely error reports, after a little digging I’ve found a solution, in addition to the code that I posted earlier about enabling the trace using C#, the web.config needs to be set as follows:

<trace enabled="true" requestLimit="100" pageOutput="false" traceMode="SortByTime" localOnly="true" />

Storing the WebException code in App_Code Dir

If you use the WebException class in an ASP.Net 2.0 site, be careful you don’t do what we did and throw the site online uncompiled with a compilation error as it won’t get reported. Luckily I found this issue on a test site but it’s still worth noting.

Personally I wouldn’t put the error reporting code in the App_Code directory as this means you’ll end up needing to maintain a plethora of files throughout various projects. Instead compile a separate DLL and include that in your projects, then if like me you find a nice addition to the error reporting code you can easily update all sites to the latest version!

Setup a simple generic test page

Nothing fancy, just a button that throws an exception will do:

TestErrorPage.aspx

<%@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void btnError_Click(object sender, EventArgs e)
    {
        throw new ArgumentException("Test Error");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Test Error Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p><asp:Button runat="server" ID="btnError" Text="Throw Error" OnClick="btnError_Click" /></p>
    </div>
    </form>
</body>
</html>

Happy Error Reporting :) -I'm hoping this is the last time I need to blog about this code but what's the betting another post is around the corner ;)

 

Don't forget to follow me on Twitter.

# Friday, March 16, 2007

Payment on acounts

Friday, March 16, 2007 1:28:52 PM (GMT Standard Time, UTC+00:00)

I recently released a mini-series of articles with a load of great business start-up advice (also available to download as a PDF) in which I talk about how the government is really going the extra mile for SMEs at the moment, helping them out in a load of different ways -really trying to encourage entrepreneurship within the United Kingdom. This was something I believed until I got my tax bill.

The deadline for your self-assessment tax return is fast approaching and the government kindly sends you an invoice for your last tax return, mine arrived just before Christmas and to my surprise it was 50% more than I submitted. Seeing as I was off to Cornwall I decided I would deal with it on my return.

I've never had an issue with paying tax, in fact I've always been proud of the fact that I've needed to pay tax, my logic is simple: if I need to pay tax, it means I'm earning! The more tax I pay, the more I've earned. See my logic?

In the past, through claiming back expenses etc my tax bills have always been relatively small and although I seem to recall something called “Payment on account”, but it was IIRC an optional payment so next year the amount you have to pay is smaller. This is a good idea. As a small business owner I do put money aside for my tax bill but that’s always been 25% of each invoice. So what’s my issue?

To me, payment on account seems like a half-arsed attempt by the government to help self-employed people out, while getting a couple more quid in the process, the issue however is I feel they’ve focused more on taking more money than helping out the self-employed people. The idea is simple: You submit your tax bill for the previous tax year, they take an additional payment (payment on account) which will go towards the next tax year, this payment is estimated on their data for you -in this case your tax bill. The first payment is due with your current tax bill, the second in July of the current tax year. Thus splitting the next year’s tax bill into two more manageable payments. -Bollocks does it. Please excuse my French but this is not at all thought out and this is why:

I would consider myself to be one of the more sensible self-employed people when it comes to saving for tax, admittedly the first couple of years I was in business I paid the tax bill with a project we had on at the time but now I do put money aside for it with every invoice (now 50% of every invoice inc VAT goes aside). So come tax return time I have a nice chunk of cash to pay for my tax bill (always more than it needs to be because of expenses etc). I then follow the governments recommendation and fill out my self-assessment tax return online in plenty of time -a word of warning, I live with a chartered accountant who helps me out with this, it’s not something I just do on my own ;). In January I have the invoice for the bill and I pay it out of my savings, anything left I can use as I wish. All good so far! As far as the government is concerned I have followed what they’re recommending and that should be it. Payment on account however throws this into turmoil. What the government IMHO neglects to tell you is that you’re going to have to pay 50% more than you’re expecting in the first year you go over their threshold.

What I don’t like about that is they’re encouraging a lot of self-employed people to complete their own return online (best to do this with an accountant really) and save for their bill but by not telling you about this additional payment they can in theory put someone out of business over night -and there’s nothing you can do about it. Take the average self-employed business owner with a turnover of £50,000. Assuming no expenses you should expect to walk away with around £38,300 (using rough maths). Cool, so you’re good and put £11,700 into savings in preparation and use the rest to pay the bills, buy a holiday, a car etc.

You think all’s dandy until at the end of the year you get a tax bill for £17,550 with a further payment of £5,850 being required in July. That leaves you with £26,600 remaining rather than the initial £38,300 you were expecting. Why? That’s simple -payment on account, the tax office say "Well, you earned £50,000 this year, so you’ll do that next year so we’ll take that money from you now, that way next year you’ll already have some money on account -helping you out. Don’t worry though, if your tax bill for next year is lower, we’ll refund the money." -there are so many issues to this statement but I’ll come back to those.

I've made a graph demonstrating the two differences. The light red segment is the amount you will need to pay in the July following your January tax payment, the dark red section must be paid in addition to your main tax bill.

Comparison between the expected tax bill and actual tax bill

Take my industry -the IT industry. It’s not unknown (or an infrequent occurrence) to have a large project (i.e. £100,000) which you can complete within a financial year. If you're already working in the sector and this £100,000 contract is your reason for going it alone this could be a serious issue for you. Ignoring how you take this money, by the end of a single fiscal year you take £100,000:

  • Turnover:£100,000
  • Tax Allowance:£5,000
  • Taxable Income:£95,000
  • Tax at 22%:£7,700
  • Tax at 40%:£24,000
  • Expected Tax Bill:£31,700
  • Expected to you:£68,300

In the event you’ve taken £100,000 for a project you’re likely to spend a fair amount of that on things like credit cards, niceties after having gone without for a while etc, so you spend a fair whack, perhaps put a chunk on your mortgage, buy a house or invest a fair chunk. Say you get the payment a couple of months before the tax year ends so you take the time off and relax a little, basically using a fair amount of the money, but you’re ok as you’ve put £32,000 into savings in preparation for your tax bill. When it comes to filing time however you’re told that you owe them an additional £15,850 with your current tax bill followed by another payment of £15,850 in July. Starting to see where my issue lies?

If you didn’t spend anymore of that £68,300 than you absolutely had to and some how had the additional £31,700 available you’re fine, but what if you decided to treat someone special, or invest the money where it’s not readily accessible, what can you do? I called the tax office to talk it through with them as I didn’t want to pay this payment on account as it would mean that things would be a little tight until the end of a current system development. The representative had absolutely no concern or understanding for my situation, when I asked her if I could spread the payments a little I was told that interest would be charged on the money if I didn’t pay it and a fine would be incurred. Furthermore she told me that this payment on account was ok because it was tax on money we had already earned (the payment on account is in theory for the current fiscal year), I did think about pointing out that a business’ earnings are not the same as a worker’s salary as they are frequently sporadic and go through highs and lows -in the case of The Site Doctor, the majority of our year’s income comes in during the final fiscal quarter.

There were a couple of things I didn’t like about the representatives statement/government’s perceived understanding of the situation:

  1. Great they are trying to help you out with your business -hopefully making the next tax year’s tax bill a smaller payment (or not at all if you think about the logic) but how does making it a forced payment without making it very well known about help?
  2. It assumes that your business’ monthly turnover is the same as an employee in that your entire year’s earnings are the same (or similar) each month with no seasonal fluctuations. I know there are some more established businesses which do have a regular income but The Site Doctor certainly doesn’t. As already mentioned, The Site Doctor has the majority of the year’s earnings paid in the final fiscal quarter -after you have to pay your tax bill!
  3. They say they’ll refund the money if your next bill is lower than the last so it’s ok. But taking the example of the £50,000 turnover above, that’s a years worth of interest on £11,700 you’ve just lost potential interest of £936 or £2,536 in the example of our £100,000 contract. Can you afford to loose out on that?
  4. This can in theory put someone out of business, as it happened, I had to pay this bill mid contract when normally I wouldn’t have had any money for a fair while, to make things worse Stacey was having a short sabbatical. Luckily we had the money in savings but if we didn’t we would have without a doubt found it hard to pay.

The solution?

I don’t like bitching and moaning about things without having some form of solution and I can understand that the government wants to get this cash into the bank and after the first year or two it makes things better for them but for goodness sake make the payment optional, perhaps offer a monthly payment option without penalties or at least inform people about this so they can make provisions for it. Had I not found this out before this tax year I would be in serious trouble. Of course, having a tax specialist do your books should have highlighted this for you -and it goes to show that just because they’re an accountant, if they’re not a specialist they may not know about something that can break the bank (I’ve got no blame for Stacey before you wonder!).

Note: These figures are derived from my own experience so please take professional advice on the matter as for all I know, there may be a sliding scale (I would hope there is) otherwise the government is killing businesses left right and centre. I’d be interested to know if anyone else knew of/has experienced this issue.

 

Don't forget to follow me on Twitter.