473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Static is REALLY Static!

In a standalone module (VB) behind my asp.net application, I have a couple
of utility routines that do a simple (fixed) data-retrieval (eg. "select
permissions from tblusers where userid=" & thisuser.

I figured I'd be smart and save multiple db calls for the same page request
by doing:

Function GetPerms() as string
Static myperms as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable for
use on the next request
else
GetPerms=myperms
endif
End Function

Well, blow me down, I find that the static values persist across different
page requests - even across multiple browser-sessions!!!

Can someone please enlighten me as to what's goin on here?

Thanks,
Paul.

Nov 19 '05 #1
2 994
There isn't too much enlightening to do...that's what static is.

It isn't tied to a page request, or a specific user...instead it's tied to
the application domain...You can read more from:
http://www.panopticoncentral.net/arc...04/19/964.aspx

Without knowing much more about what ur doing, I think you'd typically you'd
use something like the HttpCache or Session for what you are trying to
do...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Paul W" <qq*@qqq.com> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
In a standalone module (VB) behind my asp.net application, I have a couple
of utility routines that do a simple (fixed) data-retrieval (eg. "select
permissions from tblusers where userid=" & thisuser.

I figured I'd be smart and save multiple db calls for the same page
request by doing:

Function GetPerms() as string
Static myperms as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable for
use on the next request
else
GetPerms=myperms
endif
End Function

Well, blow me down, I find that the static values persist across different
page requests - even across multiple browser-sessions!!!

Can someone please enlighten me as to what's goin on here?

Thanks,
Paul.

Nov 19 '05 #2


Hi,
for some reason static variables in asp.net have application-wide scope.
It's almost the same as Application("myperms"). You could rewrite your
code:
Private myperms as string
Function GetPerms() as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable for
use on the next request
else
GetPerms=myperms
endif
End Function


Dr. Jones


On Mon, 2 May 2005 20:54:37 -0400, Paul W <qq*@qqq.com> wrote:
In a standalone module (VB) behind my asp.net application, I have a
couple
of utility routines that do a simple (fixed) data-retrieval (eg. "select
permissions from tblusers where userid=" & thisuser.

I figured I'd be smart and save multiple db calls for the same page
request
by doing:

Function GetPerms() as string
Static myperms as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable
for
use on the next request
else
GetPerms=myperms
endif
End Function

Well, blow me down, I find that the static values persist across
different
page requests - even across multiple browser-sessions!!!

Can someone please enlighten me as to what's goin on here?

Thanks,
Paul.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lkrubner | last post by:
In the code below I'm getting a parse error on this line: static $controllerForAll = new McControllerForAll(); why does this give me a parse error? I'm running PHP 4. function &...
3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
3
by: bauscharln | last post by:
hoi, I just wanted to add a static method to my interface, but that's not allowed! Is there a reason for this??? (Yes, I could make an abstract base class, but that's not what I want, since I...
6
by: rlvladbob | last post by:
Hi, I've try to access a static method using an instance instead of a class. public class test{ public static void ShowAText(string ThisText) { System.Console.WriteLine("->{0}",ThisText); }
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
5
by: Dave | last post by:
Hello, Suppose you have a class with a static property with only a get (read only). You also have code in a static constructor that sets these properties but takes 1 hour to run. Now suppose...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.