global objects

P

Paul

Hi,
I have been getting conflicting reports about creating global objects
in global.asa. I use FrontPage exclusively to edit (yes, even the
..asp files) a sub web with "<Object Runat="Server" Scope="application"
ID="dOnlineUsers" ProgID="Scripting.Dictionary"></Object>" as the
first line in global.asa. This creates a global object that is
referenced through out the sub web. Is this a good or bad practice?
What are the pros and cons of this practice? What would you suggest
as an alternative to using the "<Object Runat="Server"
Scope="application" ID="dOnlineUsers"
ProgID="Scripting.Dictionary"></Object>" if it is bad to us it?
Thanks,
Paul
 
T

Thomas A. Rowe

If you are using FP and letting it create the global.asa file, then your
file should begin with:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'==FrontPage Generated - startspan==
Dim FrontPage_UrlVars(1)
'--Project Data Connection
Application("db_ConnectionString") = "DSN=3067.db;DRIVER={Microsoft Access
Driver (*.mdb)}"
Application("db_ConnectionTimeout") = 15
Application("db_CommandTimeout") = 30
Application("db_CursorLocation") = 3
Application("db_RuntimeUserName") = ""
Application("db_RuntimePassword") = ""
'--
Application("FrontPage_UrlVars") = FrontPage_UrlVars
'==FrontPage Generated - endspan==

-------------------------------------------------------

Then I use the "Application("db_ConnectionString")" for my connection
--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
P

Paul

Hi,
Yes I get the same lines when FrontPage creates the global.asa file.
After this, I edit the global.asa file and add my own code. This
line:
<Object Runat="Server" Scope="application" ID="dOnlineUsers"
ProgID="Scripting.Dictionary"></Object>
when placed before the:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
line is used to create a global Scripting.Dictionary object.

The above assumes you did not understand that from my first post.
Please forgive me if this is not the case. The question is asking if
the use of this object as a global object in this way is a good coding
or bad coding technique.
I could interpret your response as you consider it bad and you use a
db instead. I could also think you did not understand my first
question.
I have used this method to track users that visit a site and have been
told that it is bad to create global objects like this. I am just
looking for opinions.
Thanks,
Paul
 
K

Kevin Spencer

The question of whether it is a good or bad practice in general is not
meaningful. The functionality exists to create global objects as you have.
Obviously it exists for a reason. There are situations where using a global
object is a good idea, and situations where it is not. It is simply a tool.
Using a screwdriver to drive nails doesn't make using a screwdriver a bad
idea. It's excellent for turning screws.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
T

Thomas A. Rowe

Paul,

I was trying the understand how the line got in the global.asa file to start
with.

However as far as whether or not to do this, it really depends on your
requirements.

You might want to do a few internet searches on "ASP Application Scope" for
additional info on the subject.

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
P

Paul

Hi,
In general, I completely agree with your first statement. This is the
reason why I used the global object in the first place. I am unclear
as to the rest of what you say. Are you suggesting that my use of the
Scripting.Dictionary object is like using a screwdriver to drive
nails? If so, what would you use instead?
Paul
 
P

Paul

Hi,
I currently use this object in a sub web. It has been working very
nicely for over a year. The server my web site is on just converted
to 2003 server and now it will work for a while and then just go away.
I will, at different intervals, start getting "Object not found"
errors. I can still access application and session variables and they
are all working, it is just that the object seems to become
un-instantiated. My support is saying that using this object as a
global is a bad thing to do and don't think there is a problem, thus
won't help me at all. They also said that If I didn't believe them
(that it was bad to use globals from global.asa) to ask at the
Microsoft news groups and anyone would be glad to tell me. They said
they did not have the time to explain why to me. So here I am, along
with several other posts, all revolving around this 2003 server
upgrade, and all of the new problems I can't seem to get solved doe to
it. Your response does not give me the impression that it is common
knowledge the globals are not to be used in global.asa at all. I have
always heard that it was not a good thing to create a global database
object there. I have never heard about any other global objects being
bad.

Paul
 
T

Thomas A. Rowe

Paul,

You might want to ask this in either the MS ASP, IIS or Windows server
newsgroups as really has nothing to do with using FP.

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
P

Paul

Hi,
I think I found an answer to my question here. I found an article at
the MS site that says that the Scripting.Dictionary is an Apartment
threaded object and that Apartment threaded objects should not be used
as a global object in an application (global.asa). I have searched
for a Dictionary that uses a compatible threading model with an
Application and have only found the Commerce.Dictionary that is only
available in the Commerce server. This is not available at my WPP. I
am searching for an alternate way to get this same functionality. I
wrote a class in ASP but the Application complains that it is an
Apartment threaded object and won't instantiate it. Any suggestions
besides using a DB?

Improving ASP Application Performance

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnserv/html/server03272000.asp

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top