August 2005 - Posts

A book surviving its 6th different Windows OS version
08 August 05 04:50 PM | despos | 2 comment(s)

SET AUTO FLATTERING MODE ON

Back in the summer of 1998, I would never have bet a nickel on the fact that a C++ shell programming book could be a must-read and must-have still today, in the summer of 2005. Admittedly, I don't know much about Windows Vista, if not the sardonic grins of some fellow Italian users. In Italian, pronounced it sounds like bugged Windows. (s-vista means mistake, bug, sort of).

I've been told that not even in Windows Vista the shell is entirely managed and rewritten. Which means that Windows Vista is going to be the 6.th Windows operating system that the book outlives. Which means that Paul Ballard is not that much wrong here in his top-ten list of not-chosen names for Windows Vista.

SET AUTO FLATTERING MODE OFF

Yes, the main reason of the post. If you're still interested in this book, here's a link where you at list download its source code. It still works. I'm using most of those shell and namespace extensions today on a Windows 2003 Server SP1 machine.

 

 

ASP.NET 2.0: CacheKeyDependency
08 August 05 10:07 AM | despos | 4 comment(s)

Imagine you have a master/detail page with a GridView and a DetailsView. You select a record in the DetailsView, make some changes and save. How can you have the master element--the GridView--refresh to reflect the change?

You hook up the ItemUpdated event on the DetailsView and call DataBind on the GridView control

Simple and effective. It works most of the times, but as-of-my-experience-and-coding not always. So when isn't it working? Let's take it the other way around and list when it actually works.

  • When the GridView is bound to an enumerable data source object (i.e., DataTable) and you manage caching manually (or have no caching at all)
  • When the GridView is bound to a data source control and caching is disabled.
  • When the GridView is bound to a data source control, caching is enabled, but a database cache invalidation mechanism is set up on the table.

Again, when isn't it working? When the GridView is bound to a data source control, caching is enabled, and no database invalidation is in place. Note that this is exactly the most common situation (or the easiest you fall into) as it delineates when you simply add EnableCaching=true.

When caching is enabled on a data source control, it defaults to a time-based expiration policy. Moreover, the default cache duration is set to 0 which means an infinite time. Unless you also specify a nonzero duration (in seconds), the cached data won’t never get stale and you have no way to refresh the view other than binding to another data source. If you set a cache duration, the data will be refreshed when the timeout expires, not when the data really changes. If adding a SQL cache dependency is too much work (it is usually the kind of stuff that makes a DBA jumping for joy), you can rely on a manual invalidation mechanism implemented through the CacheKeyDependency property.

This property indicates a user-defined key dependency that is linked to all data cache objects created by the data source control. All cache objects are explicitly expired when the key is expired. By removing or modifying the key specified through the CacheKeyDependency  property you can programmatically invalidate the data cached by a data source control.

As I understand, the property should be used in the following way.

<asp:SqlDataSource id="SqlDataSource1" runat="server" CacheKeyDependency="MyTestKey" ... />

void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
    Cache[SqlDataSource1.CacheKeyDependency] = someData;
}
void OnItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
  Cache.Remove(SqlDataSource1.CacheKeyDependency);
  GridView1.DataBind();
}

However, it doesn't work for me. The cache contains proper information but it is apparently detached from the cache entries created by the SqlDataSource control.

Is there anybody out there who can provide more information and shed some light? I tried to track down  CacheKeyDependency using .NET Reflector, but also this approach proved unsuccessful.

Looking forward to hear something :)

DataSet vs. Collections
04 August 05 10:50 AM | despos | 12 comment(s)

How were you writing data access code five years ago? You were likely using ADO Recordsets, that is a fairly bloated object incorporating well three distinct functionalities--server cursor, disconnected client cursor, firehose-style cursor.

Then came ADO.NET with its popular pair--DataSet and DataReader. Five years ago, the DataSet was hailed as a greatly enhanced version of the ADO Recordset. Five years ago, writing a custom collection was mostly possible through ATL but data binding in ASP application was still a dream (or a nightmare, from another perspective). Then .NET FX came with its predefined set of collection classes, DataSet, and typed DataSets.

Which one is your favorite? And more importantly, which one is the favorite for your application? As a matter of fact, the advent of the .NET Framework 2.0 and generics enables developers to generate and manage collections much more quickly and effectively then in the recent past. Still a number of other considerations apply. You can read my two cents on MSDN Magazine.

For a quick synoptic table, click here.

Keep comments coming!

 

More Posts