Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to deal with constants?

0 views
Skip to first unread message

Steve

unread,
Nov 29, 2005, 10:49:50 AM11/29/05
to
Running asp.net 2.0

I have never used global constants and I am a bit confused on the
subject.

I want to give the admin of an application a lot of control over
display.

i.e. custom error messages, number of rows displayed, etc.

Assuming that all these 'constants' are stored in a database table,
what is the best way of incorporating them into the application?

Should I used global.asax, i.e. make a call to the database, loop
through the values and declare them as constants? If so, can somebody
give me a few lines of code as an example? Are there any better ways?

Mark Rae

unread,
Nov 29, 2005, 10:55:26 AM11/29/05
to
"Steve" <bah...@iranmania.com> wrote in message
news:1133279390....@g44g2000cwa.googlegroups.com...

> Assuming that all these 'constants' are stored in a database table,
> what is the best way of incorporating them into the application?

How "constant" are they? Do they change never, occasionally, sometimes,
quite often, all the time...?

> Should I used global.asax, i.e. make a call to the database, loop
> through the values and declare them as constants? If so, can somebody
> give me a few lines of code as an example? Are there any better ways?

Whenever I have a smallish amount of static data which is accessed lots of
times in the web app, I tend to read it into a Hashtable in the
Application_Start event and thereafter read it from there rather than
constantly querying the database for the same piece of data over and over
again.

A good example of this are countries and currencies. They hardly ever
change, so it doesn't make sense to keep looking them up...


Edwin Knoppert

unread,
Nov 29, 2005, 10:54:19 AM11/29/05
to
Contants IN DB ???
Nahh.

Just create a class like class1
Public Const Hello As String = "hello"

then access it through: class1.Hello
No need to create a class instance.

Public functions:
Public Shared Function....
No need to create a class instance.


"Steve" <bah...@iranmania.com> schreef in bericht
news:1133279390....@g44g2000cwa.googlegroups.com...

Paul Gielens

unread,
Nov 29, 2005, 12:37:14 PM11/29/05
to

Hi Steve,

We use Enterprise Library 2005's configuration application block. It enables
you to store all application specific configuration information in a config
file (separate from the web.config to keep it from becoming messy) and
allows you to use a generic API provided by the configuration block to read
back values. The Enterprise Library 2005 comes with a configuration tool to
enable your application admin to modify the config files. This article
http://weblogs.asp.net/pgielens/archive/2005/05/16/406911.aspx explains how
to do this.

EntLib 2005
http://www.microsoft.com/downloads/details.aspx?FamilyId=A7D2A109-660E-444E-945A-6B32AF1581B3&displaylang=en

Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/
###

"Steve" <bah...@iranmania.com> wrote in message
news:1133279390....@g44g2000cwa.googlegroups.com...

Steve

unread,
Nov 29, 2005, 2:43:50 PM11/29/05
to
Well I am thinking it might be changed fairly frequently, once every 2
days say.

Steve

unread,
Nov 29, 2005, 2:46:13 PM11/29/05
to
I like this idea, but I don't want a non-tech admin editing a .vb file,
that's why I am think of using a database which can be updated online.

Message has been deleted

Edwin Knoppert

unread,
Nov 29, 2005, 2:58:59 PM11/29/05
to
That's really not necessary.
A simple resource text file could do.
I assume IIS/.NET will recompile resources as well when they are changed.

So a simple dummy-must-fill text file could do.
You simply drop the file once on a resource.rex (whatever it's name) part
and you are ready.

"Steve" <bah...@iranmania.com> schreef in bericht

news:1133293573.7...@o13g2000cwo.googlegroups.com...

Mark Rae

unread,
Nov 29, 2005, 7:45:39 PM11/29/05
to
"Steve" <bah...@iranmania.com> wrote in message
news:1133293430.2...@o13g2000cwo.googlegroups.com...

> Well I am thinking it might be changed fairly frequently, once every 2
> days say.

LOL! Well they're not constant, are they... :-)


0 new messages