Affect of Connection Frequency to database on webpage performance

  • Hi,

    In ASP.Net everytime a server control is clicked the execution goes to the server and then comes back. Now in such cases, should we reconnect to the SQL server everytime it goes, or just connect to the server the first time the webpage opens, and close the connection only when the webpage is closed.

    But will such a way be good for the security. I mean leaving the connection open all the time.

    Right now I am connecting every time there is a connection to the server, but this seems not so efficient.

    Please give me your opinion on the matter.

    Thanks,

    Snigdha

  • a web page is stateless; that is the code is executed on the web server, and the results are returned to the browser. the code is executed in a milliseconds, the web page does not stay "open" when you are looking at it; I think you are assuming that the connection that the web page used is still hanging around while you read the web page, and that is not the case.

    If you did not close your connection on the page, then the garbage collector will eventually pick it up and destroy it; your connection is re-established every time the web page is called, regardless.

    It is good practice to close your close your objects, set them to nothing and so that the garbage collector does not need to resort to timeouts to recover memory that the objects used, and so that connections can be properly pooled and managed.

    IIS will pool connections for reuse so that the connection can be reused, because there is a cost in opening a new connection; by default i believe a connection is reserved for 60 seconds, and then it is closed if there are no demands for a connection to the database.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • hey..

    thank a lot, all my queries resolved.

    Snigdha

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply