ColdFusion Muse

Client Variable Database and Reserved Word Alias

Mark Kruger July 8, 2009 10:25 PM ColdFusion Comments (6)

I had a question from a reader who was having trouble with his client variables database. You don't have to be using ColdFusion for long before you learn (or are told) that if you are going to use Client variables it is important to use a database and not the registry. This goes back to the old CF 5 days when client vars could cause the registry to grow to astronomic proportions before anyone would notice.

The solution to Client variable performance has always been to move them to a data source on an RDBMS (MySQL, MSSQL, Oracle etc). The process is all done using the ColdFusion Administrator. It is a bit involved but not difficult.

  • Add a datasource with create, update, insert and delete permissions.
  • On the "client variables" page, select the DSN from the drop down and click "add". Follow the instructions to set up the DSN. I always check the box to "disable" global variables because I never use them (things like "hitcount").
  • When you submit, the tables will be created and the DSN will be listed under the curiously named "Actions Storage Name Description" section where the registry and cookies are also choices.
Once your DSN is on the list it can be used to store variables - either by selecting as the "Default" storage location in CF administrator or specifying it in your Cfapplication tag.

Meanwhile, having explained the rudimentary steps for adding a client variable DSN my reader is impatience to hear his problem explained - so here goes. He created a DSN named "coldfusion" and used the steps above to insure that it was specified as the client variable DSN. He noticed immediately that the "global" variables were created, but no actual "client" variables were created. In other words, when he did something like "cfset client.user = 'bob'" it had no effect. Subsequent requests indicated that client.user did not even exist. Clearly the records were not being written to the DB.

The Fix

After some trial and error I suggested that perhaps the datasource name of "coldfusion" was the problem. Why you ask? As a rule I never use what could be a reserve word as a variable or datasource name. I surmised that "coldfusion" seemed to fit that standard so I suggested he create a new alias and try again. As soon as he did the tables began to update. The moral of the story - don't use reserve words for things like variable names or DSN's. Meanwhile, if by some confluence of events and aligning of the stars you have chosen to name your datasource for client variables "coldfusion" and you are scratching your head to figure out why it isn't working - try renaming the DSN.

  • Share:

6 Comments

  • Adam Cameron's Gravatar
    Posted By
    Adam Cameron | 7/9/09 7:42 AM
    Hi
    Interesting post, however I'd like to pull you up on this statement 'As of CFMX the "registry" is an XML file - but the principle is the same.' This is not true. On Windows (I've just tested this on my home Vista machine, but there's no evidence to suggest it's different for any other Windows version), client vars are stored in HKEY_LOCAL_MACHINE\ SOFTWARE\Macromedia\ColdFusion\CurrentVersion\Clients, if the setting is set to "registry". This is borne out by the docs, too:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/sh...

    I suspect you are using a non-Windows machine, in which case you are correct, the registry is "faked" via the file system instead.

    The registry remains a really dumb place to store one's client variables, IMO.

    --
    Adam
  • mkruger's Gravatar
    Posted By
    mkruger | 7/9/09 10:21 AM
    Adam,

    doh! I stand corrected. I actually wrote that tidbit from memory without checking to be sure and my memory told me that it was no longer in the actual registry - but I do work with all flavors of CF (Linux in particular) so I suppose my memory let me down :)

    Thanks for the correction - I appreciate it.
  • Davide's Gravatar
    Posted By
    Davide | 7/9/09 12:03 PM
    Great post!
    In addition to this, if your registry has grown to astronomic proportions with ColdFusion client variables, and you decide to use the database storage method (recommended) and want to delete all the already stored variables in the registry (HKEY_LOCAL_MACHINE\ SOFTWARE\Macromedia\ColdFusion\CurrentVersion\Clients). Just delete the whole /clients folder as ColdFusion will recreate it if it needs it again. If you attempt to open the clients folder, the registry will hang forever.
  • Mark Kruger's Gravatar
    Posted By
    Mark Kruger | 7/9/09 12:25 PM
    Thanks Davide - I've been there with that hanging registry - not fun.
  • JC's Gravatar
    Posted By
    JC | 7/13/09 6:06 PM
    more importantly, using the registry means you can't cluster CF. :)

    We've always used a pattern like ApplicationNameClientStorage for ours. Fairly straightforward.
  • snyder's Gravatar
    Posted By
    snyder | 8/24/09 5:03 PM
    I followed the steps to change client variables storage methods form registry to database. Created the database, registered the datasource, selected the database that now shows up along with the registry and cookie methods, clicked "apply" and restarted the services. Yet for some reason I never see any data in the table coldfusion created "cfdata". The server and sites are running fine. How do I tell if it's working?