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. i'm wondering how many connections i have to use ? [modified]

i'm wondering how many connections i have to use ? [modified]

Scheduled Pinned Locked Moved ASP.NET
questiondatabasehelpannouncement
6 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

    Salam , everybody know that a website is always viewed by a lot of people . each one can do all what he wants in . assuming i and you and you and .... we want to update someting in our blog or change something or anything that will need a connection to a database , this mean that we will need thousands of connections to access in the same time isn't it ? but it would be a stupide idea to use tousand of conections cuz even if it is reasonable , the database has a limite of connections isn't it ? but what i can't understand is how all these people can access in the same time i have this problem in my application , i don't know how have i to declare my connections to let everybody access the data in the same time ? i hope you undertood my question , can you tell me how please ? -- modified at 10:51 Monday 18th September, 2006

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

    N G D 3 Replies Last reply
    0
    • M Mohammed Amine

      Salam , everybody know that a website is always viewed by a lot of people . each one can do all what he wants in . assuming i and you and you and .... we want to update someting in our blog or change something or anything that will need a connection to a database , this mean that we will need thousands of connections to access in the same time isn't it ? but it would be a stupide idea to use tousand of conections cuz even if it is reasonable , the database has a limite of connections isn't it ? but what i can't understand is how all these people can access in the same time i have this problem in my application , i don't know how have i to declare my connections to let everybody access the data in the same time ? i hope you undertood my question , can you tell me how please ? -- modified at 10:51 Monday 18th September, 2006

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

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      By using the same connection string to open your connection you can take advantage to connection pooling, whereby the framework handles allocating the necessary number of connections. By opening and closing the connection only when necessary, and only as long as necessary, you should be able to avoid must problems. Consider also that it is highly unlikely that all users will be updating data at the same exact second.


      only two letters away from being an asset

      1 Reply Last reply
      0
      • M Mohammed Amine

        Salam , everybody know that a website is always viewed by a lot of people . each one can do all what he wants in . assuming i and you and you and .... we want to update someting in our blog or change something or anything that will need a connection to a database , this mean that we will need thousands of connections to access in the same time isn't it ? but it would be a stupide idea to use tousand of conections cuz even if it is reasonable , the database has a limite of connections isn't it ? but what i can't understand is how all these people can access in the same time i have this problem in my application , i don't know how have i to declare my connections to let everybody access the data in the same time ? i hope you undertood my question , can you tell me how please ? -- modified at 10:51 Monday 18th September, 2006

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

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

        You use a separate database connection for each request. That's the only reasonable way to handle multiple users. Any attempt to share connections or keep them alive from one request to another will only result in using more resources. It's true that there is a limit on the number of simultaneous connections, but that is rarely a problem unless you have written bad code. The database driver for Access has a limit of 64 simultaneous connections, and that is sufficient in most cases. If you have so many users that the number of connections is a problem, you have outgrown an Access database anyway. Well written code minimizes the time each connection is open, so that the server can handle more requests with fewer connections open at the same time. Open the connection as late as possible, get your data, and close the connection as soon as possible.

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

        M 1 Reply Last reply
        0
        • G Guffa

          You use a separate database connection for each request. That's the only reasonable way to handle multiple users. Any attempt to share connections or keep them alive from one request to another will only result in using more resources. It's true that there is a limit on the number of simultaneous connections, but that is rarely a problem unless you have written bad code. The database driver for Access has a limit of 64 simultaneous connections, and that is sufficient in most cases. If you have so many users that the number of connections is a problem, you have outgrown an Access database anyway. Well written code minimizes the time each connection is open, so that the server can handle more requests with fewer connections open at the same time. Open the connection as late as possible, get your data, and close the connection as soon as possible.

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

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

          thnx goffa, but what do you mean by using a separate connection for each reuest ? how can i do that ? i don't know may be you mean using a connection for UPDATE & 1 for select ... ? can you clearify your idea please ? thank you

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

          G 1 Reply Last reply
          0
          • M Mohammed Amine

            thnx goffa, but what do you mean by using a separate connection for each reuest ? how can i do that ? i don't know may be you mean using a connection for UPDATE & 1 for select ... ? can you clearify your idea please ? thank you

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

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

            A request is when the browser ask the server for a specific page, so what I mean is that you should create and open (and of course close) a connection object for each single page (that uses the database) that is created on the server.

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

            1 Reply Last reply
            0
            • M Mohammed Amine

              Salam , everybody know that a website is always viewed by a lot of people . each one can do all what he wants in . assuming i and you and you and .... we want to update someting in our blog or change something or anything that will need a connection to a database , this mean that we will need thousands of connections to access in the same time isn't it ? but it would be a stupide idea to use tousand of conections cuz even if it is reasonable , the database has a limite of connections isn't it ? but what i can't understand is how all these people can access in the same time i have this problem in my application , i don't know how have i to declare my connections to let everybody access the data in the same time ? i hope you undertood my question , can you tell me how please ? -- modified at 10:51 Monday 18th September, 2006

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

              D Offline
              D Offline
              deepaks3
              wrote on last edited by
              #6

              I think this kind of design pattern can help you:- using System; using System.Collections; using System.Threading; // "Singleton" class LoadBalancer { // Fields private static LoadBalancer balancer; private ArrayList servers = new ArrayList(); private Random random = new Random(); // Constructors (protected) protected LoadBalancer() { // List of available servers servers.Add( "ServerI" ); servers.Add( "ServerII" ); servers.Add( "ServerIII" ); servers.Add( "ServerIV" ); servers.Add( "ServerV" ); } // Methods public static LoadBalancer GetLoadBalancer() { // Support multithreaded applications through // "Double checked locking" pattern which avoids // locking every time the method is invoked if( balancer == null ) { // Only one thread can obtain a mutex Mutex mutex = new Mutex(); mutex.WaitOne(); if( balancer == null ) balancer = new LoadBalancer(); mutex.Close(); } return balancer; } // Properties public string Server { get { // Simple, but effective random load balancer int r = random.Next( servers.Count ); return servers[ r ].ToString(); } } } /// /// SingletonApp test /// /// public class SingletonApp { public static void Main( string[] args ) { LoadBalancer b1 = LoadBalancer.GetLoadBalancer(); LoadBalancer b2 = LoadBalancer.GetLoadBalancer(); LoadBalancer b3 = LoadBalancer.GetLoadBalancer(); LoadBalancer b4 = LoadBalancer.GetLoadBalancer(); // Same instance? if( (b1 == b2) && (b2 == b3) && (b3 == b4) ) Console.WriteLine( "Same instance" ); // Do the load balancing Console.WriteLine( b1.Server ); Console.WriteLine( b2.Server ); Console.WriteLine( b3.Server ); Console.WriteLine( b4.Server ); } }

              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