global variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I would like to store data for a specific user in multi-user environnment.
I need the data to be accessible to all class for a specific user but not the
others. In need something like a class with static variables, but for each
user independently. In a Web app it would probably be the in Session, but
it's a console app.

Thanks
 
martelpa said:
I would like to store data for a specific user in multi-user environnment.
I need the data to be accessible to all class for a specific user but not the
others. In need something like a class with static variables, but for each
user independently. In a Web app it would probably be the in Session, but
it's a console app.

It's not clear to me whether you're in a situation where there will be
multiple users within the same process for transient data, or whether
you're talking about storing data between sessions (i.e. between
shutting down the process once and starting it up again).
 
Hi,

Thanks for your reply!

Here's an example... there will be multiple users using the same app, but
each of them have a particular ConnectionString (dynamically built at runtime
with their login and pwd). The ConnectionString need to be accessble from
every Data Acess Class.

So I can't put the ConnectionString in the App.Config, because it's
different for each user. And I can't use a static variable in a "Global
Class" because they will be multiple user...

Thank
 
Hi,

I'm not sure that will work in my case. I need something like...every user
have his Singleton.

I want to build the connectionString at runtime for each user and then I
have to store it somewhere...and it need to accessble from every Data Access
Layer Class.

Thanks
 
martelpa said:
Thanks for your reply!

Here's an example... there will be multiple users using the same app, but
each of them have a particular ConnectionString (dynamically built at runtime
with their login and pwd). The ConnectionString need to be accessble from
every Data Acess Class.

You still haven't made it clear whether the multiple users will be
using the same active process at the same time (and if so, how), or
whether it's different users running the same program, but only one
user interacting with any given process.
So I can't put the ConnectionString in the App.Config, because it's
different for each user. And I can't use a static variable in a "Global
Class" because they will be multiple user...

Hopefully once you've made it clear exactly what's going on, a solution
will present itself.
 
Hi,

That's what is going on..."different users running the same program, but
only one user interacting with any given process"

Thanks
 
martelpa said:
That's what is going on..."different users running the same program, but
only one user interacting with any given process"

In which case, you can certainly use a static variable, because you'll
have one static variable for each process. The value of a static
variable isn't magically persisted between processes.

So, you just need a way of storing per-user information so you can load
it on startup. I believe the configuration classes in .NET 2 are gears
towards this. An alternative (if you're using .NET 1.1, for instance)
is to use the registry, or store a separate file in a folder specific
to each user (e.g. their docs and settings directory). See
Environment.GetFolderPath for a way of retrieving an appropriate
directory.
 
Probably Settings file can solve your issue. Settings can be segregated by
user.

If you need more security/control, you can derive from generated class.

in VS2005 just add Settings file to project.

HTH
Alex
 
Back
Top