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. General Programming
  3. C#
  4. One database Connection [modified]

One database Connection [modified]

Scheduled Pinned Locked Moved C#
databasetutorial
5 Posts 5 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.
  • S Offline
    S Offline
    Shivendra Pandey
    wrote on last edited by
    #1

    my application is Port Listener(window service) a lot of client will send data to this port in order to handle it i have used mutithreading. After receiving data from port i have to save it in database now i m using classical way to save in database like open connection save data and then close connection and dispose connection. as we know every time opening and closing connection take time . Because within a second 30 or more than 30 client is sending data to this port to this port every time opening closing connection is not idea. so please suggest how to use one connection for all request first time only it open connection and from next time my app use the open connection.

    modified on Tuesday, December 22, 2009 8:05 AM

    S A P H 4 Replies Last reply
    0
    • S Shivendra Pandey

      my application is Port Listener(window service) a lot of client will send data to this port in order to handle it i have used mutithreading. After receiving data from port i have to save it in database now i m using classical way to save in database like open connection save data and then close connection and dispose connection. as we know every time opening and closing connection take time . Because within a second 30 or more than 30 client is sending data to this port to this port every time opening closing connection is not idea. so please suggest how to use one connection for all request first time only it open connection and from next time my app use the open connection.

      modified on Tuesday, December 22, 2009 8:05 AM

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      I don't understand your question if there is any question.

      Shivendra Pandey wrote:

      It means only first time the database will open from next time it use the same open connection for every request.

      As long Connection is opened it will be used for request. However you need to handle connection timeout (Disconnected by unkown reasons).

      Shivendra Pandey wrote:

      one dedicated open connection for all request in this service

      If you use app or service as "front end" (app that sits on server and it is betwen client and database) and connect to database service than that can be acheaved. That app needs to handle a multiple connection if you want to use multiple clients at the same time

      1 Reply Last reply
      0
      • S Shivendra Pandey

        my application is Port Listener(window service) a lot of client will send data to this port in order to handle it i have used mutithreading. After receiving data from port i have to save it in database now i m using classical way to save in database like open connection save data and then close connection and dispose connection. as we know every time opening and closing connection take time . Because within a second 30 or more than 30 client is sending data to this port to this port every time opening closing connection is not idea. so please suggest how to use one connection for all request first time only it open connection and from next time my app use the open connection.

        modified on Tuesday, December 22, 2009 8:05 AM

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        So where is the problem? Its easy enough to do.

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        1 Reply Last reply
        0
        • S Shivendra Pandey

          my application is Port Listener(window service) a lot of client will send data to this port in order to handle it i have used mutithreading. After receiving data from port i have to save it in database now i m using classical way to save in database like open connection save data and then close connection and dispose connection. as we know every time opening and closing connection take time . Because within a second 30 or more than 30 client is sending data to this port to this port every time opening closing connection is not idea. so please suggest how to use one connection for all request first time only it open connection and from next time my app use the open connection.

          modified on Tuesday, December 22, 2009 8:05 AM

          P Offline
          P Offline
          Paulo Zemek
          wrote on last edited by
          #4

          Probably you don't want that. For example, if the connection is lost, what happens? If two clients try to use the connection at the same time? One client starting a transaction will in fact be starting a transaction over the connection used by everyone (for example, in Sql Server if there is a transaction, you must use it). And, finally, there is the connection pooling. By default, when you open and close a connection, the real connection keeps opened, but it is returned to the pool. Opening it again will only use the already opened connection. So, the best practice is to open the connection for each web-method and close it at the end. You can, of course, configure the maximum pool size to 1, so only one real connection will be kept open.

          1 Reply Last reply
          0
          • S Shivendra Pandey

            my application is Port Listener(window service) a lot of client will send data to this port in order to handle it i have used mutithreading. After receiving data from port i have to save it in database now i m using classical way to save in database like open connection save data and then close connection and dispose connection. as we know every time opening and closing connection take time . Because within a second 30 or more than 30 client is sending data to this port to this port every time opening closing connection is not idea. so please suggest how to use one connection for all request first time only it open connection and from next time my app use the open connection.

            modified on Tuesday, December 22, 2009 8:05 AM

            H Offline
            H Offline
            hosseinghazanfary
            wrote on last edited by
            #5

            i think u should create and open the connection when your windows service starts,so during the process everywhere in your code u can use that open connection.

            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