Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2004, 04:59 AM
Registered User
 
Join Date: Jun 2004
Location: , , Iran.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar thank you for your complete answer
I don't want to insist on such abstract concept
but...(!!!)
I think when an ASP.NET application installed into a server and when users access it for each user there will be an instance of the webapplication but I don't know much about such instances for example
whether evry variable(gloabls or loacals like connection objects) is putted in this instance in the memory of user's machine, or only one unique variable would exist in IIS in the server
Imar supose my site have only one page(index.aspx)in this page I declare a connection as
a Global or Local connection and in my Page_Load, first I create the connection(by new method)then connect to database
and with a reader object I read lots of records from the connection and then I close my connection
now according to your answer you meant for global one the multi-tasking is not enabled
but for local one multi-tasking is enabled
you know in the above example when I don't need connection(Gloabl or Local)I close it(myConnectionObject.Close());then why multi-tasking can't work here
Imar excuse me because of my curiosity


 
Old July 9th, 2004, 05:11 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not sure what exactly you mean by multi-tasking etc enabled in this context.

But anyway, if you create a connection in Page_Load, then each user requesting that page gets his or her own connection, because they are dealing with a page instance, which is a unique / separate object for each user.

However, if you define a static connection in the Global class or anywhere else, that connection applies to the entire application. The entire application in this context means really the entire application, not just the current user's request. So, with a global connection all users share that connection. With a connection in Page_Load all users get their own connection.

I think you're missing the point a bit about opening and closing a connection in your Global class. Sure, when you close the global connection, it becomes available for other users, but in sequential manner. User number 2 has to wait until user 1 is ready. When you define a local connection (as opposed to a global one), they can access the datastore simultaneously.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: U.F.Orb by The Orb (Track 2 from the album: U.F.Orb) What's This?
 
Old July 9th, 2004, 05:56 AM
Registered User
 
Join Date: Jun 2004
Location: , , Iran.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have gotten evry thing now
Therefore a static field(in the project's scope) is a unique field for all users
and all the multi-tasking and simultaneity and asynchronism about my connection object based on the above sentence.
Thank you very much.
Best Wishes.

 
Old July 9th, 2004, 07:43 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'd like to throw in a thought here if it hasn't been covered already.

It has been stated that "when I don't need connection(Gloabl or Local)I close it(myConnectionObject.Close())". What happens when one page process closes the global connection object while another page process is still using it? This isn't such a good idea.
 
Old July 9th, 2004, 08:11 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Interesting thought. Hadn't even thought about that. That would quickly get you in major troubles as well.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Untitled by Eels (Track 15 from the album: Daisies Of The Galaxy) What's This?
 
Old July 9th, 2004, 09:08 AM
Registered User
 
Join Date: Jun 2004
Location: , , Iran.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to planio for his attention
when I were writing that thread ("when I don't need connection(Gloabl or Local)I close it(myConnectionObject.Close())" I didn't know exactly my Global connection is unique in all of my application....
but because of Imar's help I have understanded now....
Therefore you are righrt ,when a global connection closes for a user maybe(surely) for another user using it causes some problem(but I didn't know it about three hours ago)
did you know this site we discussed about only had one user(myself)
no problem!!!!:D:D
With lots of thanks

 
Old July 12th, 2004, 01:15 PM
Authorized User
 
Join Date: Jul 2004
Location: East Rutherford, nj, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Mayur52o
Default

if you don't want to make an instance of the class everywhere do this.

namespace myProject
{
  public class Globals
  {
    public static string connectionString = "Bla bla bla, your ConnectionString here";
  }
}

You can acces this variable form another class like this.

Globals.connectionString;

If you don't want to make a new instance everytime this is one way you can access the variable from other forms.


 
Old March 2nd, 2005, 02:07 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

melvik,

1) Create a class where your ConnectionString variable can be set and get as mentioned

2) If you want to use this class as a 'global' class, so that your application 'sees' this class in the same state, then, 'pass' this class around using setter/getter method...


ex.

//Inside the Startup, for example, it will initialize the XClass once.
XClass xClass = new XClass();


// set and get whatever you need
xClass.ConnStr = "bla bla bla";

// before calling the form1, 'pass' on the class
form1.XClass = xClass
form1.Show


Inside a form1:
XClass xClass = null;

public XClass XClass
{
    get {xClass;}
    set {xClass = value;}
}


I hope this helps.




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
comapring global variable value to local variable amhicraig XSLT 6 December 5th, 2007 12:16 PM
Global Variable techfreak123 XSLT 0 August 3rd, 2006 07:45 AM
global variable? milk_vanilla Classic ASP Basics 3 January 8th, 2005 06:50 PM
global variable in c# kobystud C# 3 April 22nd, 2004 05:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.