Discussion Locked

Active server connection

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
When should i open a database connection in an asp application should i open a connection for every session start or open the connection in every page which require the database connection

3 replies

by basit_jafri

Hi

The opening and closing of the connections totally depends upon the application. The requirements will give u the answer

If u need a connection in a page which will just take input from the user and that's it, then u can think of opening a connection in the page and close it there.

If u are interacting with the user and the conversation continues for a few pages, then it will be appropriate to go for openeing it with the session

The best way to do it will be making a connection pool like module or something which will be responsible for keeping the number of connections ur application needs and then terminating connections if they are no more needed. The reason of more robustness of this architecture is that its not necessary that there is only a few ppl on ur site at a time. For example , your site has a registration page taking information about your site members. There is a possibility that at the same time 50 ppl are registering and according to what we discussed above, if we are opening one connection on this page (as no more interaction needed) then 50 connections will open at a time. On the other hand, if we have a connectino pool and we just let the pool manage the connections, then there is a possibility that due to the slow responses and typing time of the users, only 10 connections are needed bye the same 50 pages. So if ur planning to make something big, opening one connection per page is killing your server.

Hope it helps

BAJ

This discussion is closed to new replies.