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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Is it required to open and close the data connection for every database operation?

Is it required to open and close the data connection for every database operation?

Scheduled Pinned Locked Moved ASP.NET
questiondatabase
5 Posts 3 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
    Mic Mathi
    wrote on last edited by
    #1

    I was a windows application programmer. I am newbie in web. What i did in windows application is that the database connection will implemented at the time of start up the program. But when i started the work on web application i got an advice to open and close the database connection for every database operation. As an explanation they said it is the safest method. But what is the risk? I searched some time in Google i couldn't find a good answer. Can i store sqlconnection object in application variables? Or is there any other good method? Can i get any useful links for this? Thanks and regards

    Ken,Mexico(Guanajuato)

    G 1 Reply Last reply
    0
    • M Mic Mathi

      I was a windows application programmer. I am newbie in web. What i did in windows application is that the database connection will implemented at the time of start up the program. But when i started the work on web application i got an advice to open and close the database connection for every database operation. As an explanation they said it is the safest method. But what is the risk? I searched some time in Google i couldn't find a good answer. Can i store sqlconnection object in application variables? Or is there any other good method? Can i get any useful links for this? Thanks and regards

      Ken,Mexico(Guanajuato)

      G Offline
      G Offline
      ganeshkuppuswamy
      wrote on last edited by
      #2

      you are using asp.net(c# or vb) coding language ,Whatever may be if you are asp.net the you can use webconfig file to declare connection and you can use the single connection where ever you want in your project.

      ganeshk

      M 1 Reply Last reply
      0
      • G ganeshkuppuswamy

        you are using asp.net(c# or vb) coding language ,Whatever may be if you are asp.net the you can use webconfig file to declare connection and you can use the single connection where ever you want in your project.

        ganeshk

        M Offline
        M Offline
        Mic Mathi
        wrote on last edited by
        #3

        Yes i am following this method. I wrote the connection string in web.config file. But what is my problem that opening database connection each time makes my site slow. I noticed that some of the functions are slow because it take 1 or 2 seconds to open a connection. Thanks and regards

        Ken,Mexico(Guanajuato)

        B 1 Reply Last reply
        0
        • M Mic Mathi

          Yes i am following this method. I wrote the connection string in web.config file. But what is my problem that opening database connection each time makes my site slow. I noticed that some of the functions are slow because it take 1 or 2 seconds to open a connection. Thanks and regards

          Ken,Mexico(Guanajuato)

          B Offline
          B Offline
          Brady Kelly
          wrote on last edited by
          #4

          That doesn't sound right. You should be enjoying connection pooling[^] as automatically provided by ADO.NET.

          M 1 Reply Last reply
          0
          • B Brady Kelly

            That doesn't sound right. You should be enjoying connection pooling[^] as automatically provided by ADO.NET.

            M Offline
            M Offline
            Mic Mathi
            wrote on last edited by
            #5

            Thanks for that link. Actually i was blind on this problem. Now i got a thread. Let me to read that article for creating a systematic database connection. Thanks and regards

            Ken,Mexico(Guanajuato)

            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