But in between the page calls there is a lot of time where the connection
isn't doing anything. And let's say you have 200 users going to your site -
you are going to keep 200 connections open at all times? This would be if
you were doing it by user, not one global connection that was being done
here (as that would fail for thread concurrency reasons, as one connection
can only execute one query at a time). And you would have to clean it up in
Session_End - but what is the length of the session? The default 20 minutes?
Or 2 hours? So you have a user come in, view a page, and then leave, but
the session is still there. So for the next 2 hours you have an open
database connection just sitting there, while others users are trying to
connect? Which they won't be able to, if you are giving hundreds of users
their own personal database connection that remains open for the lifetime of
the session.
Rudi Ahlers said:
But this is quite a valid question:
What happens if you do have a website is is DB driven only. Each page makes
DB constant calls, thus not really releaving the server of it's load?
Does it really free up some reasources if you op the page (which does
the
DB
quesries) view it, and the click on another page, which queries the DB yet
again?
--
Kind Regards
Rudi Ahlers
+27 (82) 926 1689
For as he thinks in his heart, so he is. ... (Proverbs 23:7)
Hi,
Thank you very much for your quick answer.
I want to know what the problem is if "The connection is always open, and
never closed". Does it reduce the performance of the server?
Q.
Marina said:
No, that's a terrible horrible way to do it.
1) You have one instances of the connection, being shared by ALL users of
your application. Invariably, two users will do something that will cause
the server to try to use that connection at the same time, and one of the
users will get an error.
2) The connection is always open, and never closed. You should keep the
connection open for just as long as you need it, and then close.
A better way would be to have common routines that get/save data, and then
all the pages call these routines to do work for the. Each routine creates
and opens a connection, does its work, and then closes it.
Hi:
Almost all my pages get data from the database, so is it a good way that
open a sql connection when application starts in the global.aspx, like
this:
protected void Application_Start(Object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("......");
conn.Open();
Application["myConnection"] = conn;
}
so that I can use this connection in each page, like:
SqlDataAdapter myAdapter =
new SqlDataAdapter(sqlString,
(SqlConnection)Application["myConnection"]);
or I make a connection in each page?
Which one is better?
Thanks
Q.