1

I am using the following code in my global.asa Application_Start event. My question is, do I need to do anything special so this application variable is usable across a web farm, since my classic ASP app is hosted on a web farm?

Sub Application_OnStart
 companies.add "a", "Athens"
 companies.add "b", "Belgrade"
 companies.add "c", "Cairo"
 set Application("companies") = companies
End Sub
Rich
  • 5,603
  • 9
  • 39
  • 61
Sunil
  • 20,653
  • 28
  • 112
  • 197

1 Answers1

1

Assumptions:

  1. you have simply forgotten to show the declaraion and assigning of an instance of an object to the companies variable.
  2. that this object is free-threaded but has the STA marshalling proxy needed to make objects in the Application object usuable.
  3. You are simply loading this object with cached data to improve performance. I.e., you aren't expecting to update it during processing of requests and have that data available to subsquent requests.

Where the above assumptions are all true then you are good to go. If any are false you have a problem.

If you have a problem with the first two then you have a problem with or without a web farm so you should be able to test that before depolyment.

If you have a problem with the third assumption then you are going to need the help of a backing DB, and some other plumbing.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Very nice explanation. I think in a web farm, the Application_Start event will occur on each web server separately, and whenever this event occurs on each web server, then Application("companies") will get populated for that web server. So, it seems each web server will have its own separate Application("companies") variable, rather than a single shared application variable being used by all web servers. – Sunil Apr 15 '12 at 05:18
  • Also, another strange is that I can use 'companies' variable on any ASP page and it will show the correct values. Then, what is the use of Application("companies") variable? It's a bit confusing. – Sunil Apr 15 '12 at 05:19
  • @Sunil: The scope the "Application" object is the process hosting the ASP application. Where Web Farms and Web Gardens are concerned there are multiple processes and therefore multiple application object instances. Your second comment makes no sense. – AnthonyWJones Apr 15 '12 at 17:31
  • I meant to say, that if I populate a variable in Applicatio_Start event, then it seems to be available in all other ASP pages. That is confusing to me, since Application("companies") should be freely available in all ASP pages and not the usual 'companies' variable. I observed this while stepping through code in VS 2010. But may be, I was missing something. – Sunil Apr 16 '12 at 05:18
  • @Sunil from the code shown it appears that `comapies` is a global variable. From the `add` method I presume you are using a `Dictionary` object. Take a look at Anthony's answer in the following [SO](http://stackoverflow.com/questions/1805453/caching-recordsets-in-asp-classic) for some warnings. – Guido Gautier Apr 17 '12 at 09:37