Have you ever done a presentation when….

October 6, 2006

…your laptop dies, the replacement laptop looks like it’s about to die, the internet connection might as well be dead, and finally your application looks like it’s dying too.

Well has just happened in the presentation I just did, or tried to do to be more accurate!

It’s been an easy week, tweeking the application for the final review presentation for my favorite client, it was supposed to be a swift in and out, everybody leaves chuffed with themselves at the close of a successful project.

Silly me, thinking it was gonna be that easy.

So this morning it I start off giving the css a quick polish ahead of the meeting, making sure everything is working as it should. Then me & my boos head off safe in the knowledge the site is working perfectly. We arrive at our clients, with the laptop we were asked to bring last minute (just grabbing the nearest one as were leaving). We are shown into he boardroom, clients sat round a huge table, massive 42″ plasma at the head, waiting for our laptop to plug into.

First hiccup – As we’re plugging everything in my boss tries to plug in the power cable, doesn’t fit – cables must have got mixed up, never mind, must have at least an hours battery time.

Second hiccup, takes 10 mins hook up the plasma.
Third hiccup, no network, need IT to enter the proxy server settings.

At last were up and running, oh no what’s happened to the site!

What!! how can this be, I was just on it half an hour ago!

‘Cannot connect, SQL Server 2005 does not allow remote connections’

Few phone calls later we figure out it must be a problem with firewall, quick call to the hosting company we use,
bish bash bosh – were up an running, limping heavly by now.

10 mins in, laptop dies, quick plug in the power, shit it’s not the right cable!
So we have to use someones laptop in the office, the only laptop available, a Polish designers machine, everything’s in Polish, including an obscure Polish browser, no IE, no Firefox.
So hesitantly open up this browser, phew, everything is in the right place.
As we are going through the site, it starts getting slower and slower, till the point where it was taking 20 seconds to load up a basic page.
The excuses start from out hosts about poor connection speeds, meanwhile out clients are asuming it must be the site that’s really slow, not good!
During this time, the Polish guy who’s laptop it is has been sitting in, playing with his mobile the entire time,
bip, bip, bip. Then he starts playing with the wall mounted air conditioning unit with the remote, turning it up and down, eventually settling for freezing.

We decided to call it a day, and re-schedule for a meeting at our offices, where we eliminate this scenario from ever happening again.

I’m off for a beer now,



What’s New

September 21, 2006

Well, busy old week in which to start my blog, but I’ve been trying to make start blogging for ages so I thought sod it, just start.

Just coming to the end of my first commercial project for my new employers (www.fmedia.co.uk), a site for a ‘world leader‘ in transport fabric production, basically they make the seat fabric for buses, coaches & trains.
If you look at the site you’ll see some spectacular fabric designs – www.holdsworth.co.uk

The designers have done a good job as site looks really nice with some nice little features. Plus it gave me the chance to test out some new ideas and explore some of the new features of .NET 2 & SQL Server 2005.

Perhaps one of the best features of .NET 2 & SQL 2005 is the SQL Cache Dependancy technology, this enables us to cache data in memory and then automatically invalidate the cached data when the underlying data source has changed.

It’s really easy to set up as well, you can use it the drag and drop DataSource way, but this is alot less flexible than doing it programmatically, doing it in code is when it becomes really powerful, giving you fine grain control over what is cached, for how long and then the killer bit – you can specify multiple dependancies of any type, which can be any object, a database table or a physical file!

To set up cache dependancies for SQL Server 2005 (you can do it with 2000 with a little more plumbing) you will need to enable notifications for the database you are using. There is an easy command line tool that ships with the v2 Framework that allows us to enable the database and the tables we are interested in using a few simple commands. You can also enable notifications programmatically, which means we can include this procedure of enabling notifications in our application set up routines. There is a third way of setting it up, by executing a bunch of stored procedures.

So you have a choice of ways to enable notifications on your database, by far the quickest and easiest way is to use command line tool – aspnet_regsql.exe which you can find in C:\WINDOWS\Microsoft.NET Framework\v2.0****\

Enabling Cache Notifications in SQL Server 2005 using aspnet_regsql

1) Open the command prompt and change the directory to v2 framework root directory

C:\> cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

2) Run aspnet_regsql to enable notifications on your database

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S dbServerInstance -U usr -P pwd -d “mydb” -ed

* This only needs to be done once for each database

2) Enable notifications for the tables you want to have dependancies on

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S dbServerInstance -U usr -P pwd -d “mydb” -et -t “TableName”

3) Register the notifcation in the web.config file for the application

<sqlCacheDependency enabled=”true” pollTime=”1000″ >
<add name=”mydb” connectionStringName=”MyConnection” />

The Poll time attribute specifies how often the application checks to see whether the data has changed or not.

Now that we have set up the database for query notifications we are ready to start caching some stuff.

Adding items to the cache with dependancies

To programmatically add and item to the cache we need pass an object and its dependancy reference to the Cache.insert method. Next we are going to add a SqlCacheDependancy to the to an object.


Here we are adding a generic List of MyDataObject to the cache specifying the MyDataTable as a dependancy, so that when data in the MyDataTable database table changes the cached version of MyDataObject will be invalidated.

private void AddToCache(List<MyDataObject> myObjects)
   System.Web.Caching.SqlCacheDependency dependantData = new System.Web.Caching.SqlCacheDependency(“MyConnection”, “MyDataTable”);
   Cache.Insert(“CacheKey”, myObjects, dependantData, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration);

Next we have a method to retreive the MyDataObject List from the cache

private void GetCachedObject()
   return Cache[“CacheKey”] as List<MyDataObject>;

Next, here we have out load method which retreives the cached MyDataObject List if it exists, if not we get it from the database and cache the List

private void Load()
   List<MyDataObject> myObjects = GetCachedObject();
   // Check if the item was retreived from the cache
   if(myObjects == null)
      // Fill the list from the database
      myObjects = DbProvider.GetMyDataObjects();
    myDataList.DataSource = myObjects;

So there we have it, the basics of using the cache dependancies.

I will be posting more very soonon assigning multiple dependancies to an object, hopefully this will help you get started