Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. where can i declare a global variable ?

where can i declare a global variable ?

Scheduled Pinned Locked Moved ASP.NET
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohammed Amine
    wrote on last edited by
    #1

    Hi , please i have a small problem right here , i need to declare a connection & a dataset & also an adapter variables within ma application but i want to use just 1 variable in those ones in each session that mean all the pages in 1 session will use 1 variable that mean this variable havs to be public or global or i don't know , i just tried to declare it in the module in vs2003 but in the web devoloper 2005 there is no module item , even with that module it doesn't work can somebody help me ?

    try to be good if you can't be the best

    T G A 3 Replies Last reply
    0
    • M Mohammed Amine

      Hi , please i have a small problem right here , i need to declare a connection & a dataset & also an adapter variables within ma application but i want to use just 1 variable in those ones in each session that mean all the pages in 1 session will use 1 variable that mean this variable havs to be public or global or i don't know , i just tried to declare it in the module in vs2003 but in the web devoloper 2005 there is no module item , even with that module it doesn't work can somebody help me ?

      try to be good if you can't be the best

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      Store your variable in session state. After retreiving the variable from session state you can pass it as an arguement to whatever method / function you want. You need to read up on ASP.Net development. Check these links for more info. http://msdn.microsoft.com/msdnmag/issues/05/09/SessionState/default.aspx http://msdn.microsoft.com/asp.net/learning/learn/newtodevelopment/

      how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      1 Reply Last reply
      0
      • M Mohammed Amine

        Hi , please i have a small problem right here , i need to declare a connection & a dataset & also an adapter variables within ma application but i want to use just 1 variable in those ones in each session that mean all the pages in 1 session will use 1 variable that mean this variable havs to be public or global or i don't know , i just tried to declare it in the module in vs2003 but in the web devoloper 2005 there is no module item , even with that module it doesn't work can somebody help me ?

        try to be good if you can't be the best

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Why do you think that you need that? Session state is not a very good place for database objects. Declare them where you use them.

        --- b { font-weight: normal; }

        M 1 Reply Last reply
        0
        • G Guffa

          Why do you think that you need that? Session state is not a very good place for database objects. Declare them where you use them.

          --- b { font-weight: normal; }

          M Offline
          M Offline
          Mohammed Amine
          wrote on last edited by
          #4

          well, if i declare them when i use them then i can't use one coonnection in all my pages , i will create 1 connection for each page or at leat to reinitialize the same connection in all the pages but what i wantis to declare it once do you have a suggestion

          try to be good if you can't be the best

          G 1 Reply Last reply
          0
          • M Mohammed Amine

            Hi , please i have a small problem right here , i need to declare a connection & a dataset & also an adapter variables within ma application but i want to use just 1 variable in those ones in each session that mean all the pages in 1 session will use 1 variable that mean this variable havs to be public or global or i don't know , i just tried to declare it in the module in vs2003 but in the web devoloper 2005 there is no module item , even with that module it doesn't work can somebody help me ?

            try to be good if you can't be the best

            A Offline
            A Offline
            albCode
            wrote on last edited by
            #5

            . . . public partial class MyPage: System.Web.UI.Page { public SqlConnection sqlConn = new SqlConnection(); public DataSet ds = new DataSet(); public SqlDataAdapter sqlAdapter = new SqlDataAdapeter(); . . . . . }

            M 1 Reply Last reply
            0
            • A albCode

              . . . public partial class MyPage: System.Web.UI.Page { public SqlConnection sqlConn = new SqlConnection(); public DataSet ds = new DataSet(); public SqlDataAdapter sqlAdapter = new SqlDataAdapeter(); . . . . . }

              M Offline
              M Offline
              Mohammed Amine
              wrote on last edited by
              #6

              this doesn't do the jojb i tried exactlly this code with public visibility but it doesn't work any ideas ?

              try to be good if you can't be the best

              1 Reply Last reply
              0
              • M Mohammed Amine

                well, if i declare them when i use them then i can't use one coonnection in all my pages , i will create 1 connection for each page or at leat to reinitialize the same connection in all the pages but what i wantis to declare it once do you have a suggestion

                try to be good if you can't be the best

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                To use one connection for all pages is a really REALLY bad idea. The result is one (or more) of these: :: Only one user at a time can use the site, as the connection will be busy. :: You will get conflicts when more than one request uses the same connection. :: If you use one connection per user, the number of users can never be more than the number of simultaneous connections that the database accepts. :: The connection will time out and close automatically after a few minutes.

                --- b { font-weight: normal; }

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups