473,414 Members | 1,667 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,414 software developers and data experts.

static class confirmation

Using ASP.NET 2.0 and Visual Studio 2005

I have website and a DLL attached to it (BusLayer). The class inside the
dll (also imaginatively named BusLayer) havea number of static
variables. One example:

public static connectionString;

Website is running from IIS.

Am I right in saying that this BusLayer class is shared amongst ALL
intances of my website. If I access the site from my PC, and a friend
accesses from a different PC, then we are using the same variable called
connectionString?

I ran a test and put a line of trace in the static constructor (the
whole class is static) and this line was only written out once, even
when I had multiple users access my site.

Thanks in advance.

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Mar 15 '06 #1
14 1422
I think your right there, i just tried this on one of our IIS servers and
the same behaviour appeared.

I think because the connection string is not changing asp.net is intellegent
enough not to need to recreate the class for multiple users.

If you actually change the ConnectionString property and then push this out
to your live server, all users on your server will actually be forced to
refresh there current session and all there Session variables are cleared.

This is actually quite clever and will be changing a number of things on our
own website to take this behaviour into account.

Regards

"Steven Blair" <st**********@btinternet.com> wrote in message
news:eF**************@TK2MSFTNGP14.phx.gbl...
Using ASP.NET 2.0 and Visual Studio 2005

I have website and a DLL attached to it (BusLayer). The class inside the
dll (also imaginatively named BusLayer) havea number of static
variables. One example:

public static connectionString;

Website is running from IIS.

Am I right in saying that this BusLayer class is shared amongst ALL
intances of my website. If I access the site from my PC, and a friend
accesses from a different PC, then we are using the same variable called
connectionString?

I ran a test and put a line of trace in the static constructor (the
whole class is static) and this line was only written out once, even
when I had multiple users access my site.

Thanks in advance.

Steven

*** Sent via Developersdex http://www.developersdex.com ***

Mar 15 '06 #2
Yup,

Originally I was creating a new instance of BusLayer each time a user
hit the website until I discovered this.
Unfortunately, the requirements have change slightly and having one
instance of the connectionString is no longer an option. Each user could
in thoery have their own connectionString so I need to cater for this
scenario.

*** Sent via Developersdex http://www.developersdex.com ***
Mar 15 '06 #3
I just re-read what you replied.

The class isn't in the Session though, I access it like:

BusLayer.connectionString;

If User 1 logged in:

connectionString = "myString1";

The if user 2 logged in:

connectionString = "myString2"; //Overwrites User 1?

*** Sent via Developersdex http://www.developersdex.com ***
Mar 15 '06 #4
Steven,

Unfortunatly this is the same requirement we have, dependant on the systems
the user can access and the subscription level, they could and do have a
different connection string.

We at first built these into the DLL's (Assemblies) for the website, but
because the system has to stay live 24/7 we had to change this to reading
the connection string from a database because when you post new assemblies
to a live server, it causes the client side variables to be reset and the
user directed straight back to the hompage as soon as they click on a link.

Regards
Scott blood
C# Developer

"Steven Blair" <st**********@btinternet.com> wrote in message
news:e4**************@TK2MSFTNGP09.phx.gbl...
Yup,

Originally I was creating a new instance of BusLayer each time a user
hit the website until I discovered this.
Unfortunately, the requirements have change slightly and having one
instance of the connectionString is no longer an option. Each user could
in thoery have their own connectionString so I need to cater for this
scenario.

*** Sent via Developersdex http://www.developersdex.com ***

Mar 15 '06 #5
Isnt the assembly in which the class is located stored on your IIS server
and forms part of your web project?

Regards

"Steven Blair" <st**********@btinternet.com> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
I just re-read what you replied.

The class isn't in the Session though, I access it like:

BusLayer.connectionString;

If User 1 logged in:

connectionString = "myString1";

The if user 2 logged in:

connectionString = "myString2"; //Overwrites User 1?

*** Sent via Developersdex http://www.developersdex.com ***

Mar 15 '06 #6
I will have to make some quick changes now. I think holding the current
users conenction string in the Session might be the best approach since
there are a number of other values I need to hold.

It also raises another question for me:

Is my dll thread safe now, since multiple users are accessing the one
instance of the class. I just hadn't considered this before since I
though each user had their own copy of the dll.

Thanks for the input on this Scott.
*** Sent via Developersdex http://www.developersdex.com ***
Mar 15 '06 #7
Hi,
Am I right in saying that this BusLayer class is shared amongst ALL
intances of my website. If I access the site from my PC, and a friend
accesses from a different PC, then we are using the same variable called
connectionString?


In short, yes.

The reason is that each web app create only one appdomain, and static are
bounded to AppDomain, that;s why all your request share the same variable ,
each request is simply a new thread in your web app.

a ConnectionString is a very good candidate for static, you should assign it
only once ( in global.asax in the Application_Start ) and from there on it's
readonly. Most of the time you read the info from web.config

Remember if one of those static variables are updated during the course of
the app that you should take concurrency into consideration.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 15 '06 #8
Hi,

"scott blood" <sc*********@hotmail.com> wrote in message
news:uz**************@TK2MSFTNGP14.phx.gbl...
I think your right there, i just tried this on one of our IIS servers and
the same behaviour appeared.
Beware of this kind of tests, you can get just circumstantials results.
I think because the connection string is not changing asp.net is
intellegent enough not to need to recreate the class for multiple users.
Not at all ! it has nothing to do with "I guess" it has all to do with the
way static are created.
If you actually change the ConnectionString property and then push this
out to your live server, all users on your server will actually be forced
to refresh there current session and all there Session variables are
cleared.


No really, well it does has that effect but not for that reason. When you
change either your web.config or any dll (or even any file) inside your bin
directory the app is recycled. This has the consequence that all the
sessions are lost.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 15 '06 #9
Hi,
"Steven Blair" <st**********@btinternet.com> wrote in message
news:e4**************@TK2MSFTNGP09.phx.gbl...
Yup,

Originally I was creating a new instance of BusLayer each time a user
hit the website until I discovered this.
Unfortunately, the requirements have change slightly and having one
instance of the connectionString is no longer an option. Each user could
in thoery have their own connectionString so I need to cater for this
scenario.


Why each user needs a different connectionstring?
Even if they have different privileges you can use the very same
connectionstring, it's a business rule who access what, and should therefore
be enforced in your dll.

note that if each use has a different connectionstring you cannot pool them,
hence each request will create a new connection to the DB and the
scalability of your system is not going to be good.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 15 '06 #10
The application is really a front for a several different Databases and
depending on the login determines the Database it needs to go to.

*** Sent via Developersdex http://www.developersdex.com ***
Mar 15 '06 #11

Ignacio Machin ( .NET/ C# MVP ) wrote:
Why each user needs a different connectionstring?
Even if they have different privileges you can use the very same
connectionstring, it's a business rule who access what, and should therefore
be enforced in your dll.


Good security calls for security all the way up the chain, even at the
database layer.

Imagine someone got ahold of that connection string; they could now
have free reign to exectute any sql they wanted. Secuirty, to be
effective, must be present in every layer.

Andy

Mar 15 '06 #12
hi

then you need a connectionstring per database
"Steven Blair" <st**********@btinternet.com> wrote in message
news:un*************@TK2MSFTNGP12.phx.gbl...
The application is really a front for a several different Databases and
depending on the login determines the Database it needs to go to.

*** Sent via Developersdex http://www.developersdex.com ***

Mar 15 '06 #13
Hi,

Good security calls for security all the way up the chain, even at the
database layer.

Imagine someone got ahold of that connection string; they could now
have free reign to exectute any sql they wanted. Secuirty, to be
effective, must be present in every layer.


That's true, but creating one connection string per user using the system is
overkill, maybe creating one per role when it makes sense is a good
compromise
Mar 15 '06 #14
Ya, i'd agree with the one per role route. Ideally you can use SSPI,
but that's not always possible.

Mar 16 '06 #15

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

Similar topics

2
by: tekenenSPAM | last post by:
I know that one cannot cast a non-static member function to a void *. (http://users.utu.fi/sisasa/oasis/cppfaq/pointers-to-members.html) However, I have a case where I need to call a certain...
3
by: Philippe Guglielmetti | last post by:
Look at these few lines of code: class A { public: virtual void f() { cout << "A";}}; class B : public A{public: static void f() { cout << "B"; }}; class C : public B{public: void f() { cout <<...
5
by: Baget | last post by:
Hello this code does not compile on VC6, it compile fine on other compilers on two OS (gcc, bcc, VC7 on windows, gcc on Linux). I am getting error C2057 on VC6 what to do? ==========...
6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
2
by: S | last post by:
Hi there, I'm building an application that makes heavy use of centralized static methods (and variables) and would just appreciate hearing someone grade my understanding of the concept. In...
12
by: fox | last post by:
How do I (portably) make a forward reference to a static (I mean file-scope) variable? I've been using "extern" for years, for example: extern int x; int foo(void) { return x++; }
2
by: bienwell | last post by:
Hi all, I still have a problem when using Confirmation box in ASP.NET program. I need to get the value return of YES or NO from confirmation box in Sub function of VB program to do some tasks....
13
by: learning | last post by:
Hi I have a static class written by other team which encapsulates a database instance. but I need to extend it to incldue other things. I know that C# static class is sealed and can;t be inherited...
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...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.