Click to See Complete Forum and Search --> : URGENT!! only one connection per site


demian666
November 13th, 2009, 04:50 AM
Hi.
I've got an simple WebSite made in asp.net with c#
The web make this:
Open connection (keep for the same session)
make an simple select
Close connection (when logout)

I need to know if it is posible to have only one connection per every sessions we make.

you know: if connection==close
open conection
else
get connection

use conecction

if louout and I0m the last connection
close connection

end

Somethig like that

Thanks...it's very urgent

Shuja Ali
November 13th, 2009, 02:03 PM
I guess you haven't heard of a connection pool till now. There is no need to keep a connection open. Open the connection, do your work, close it and when you try to open it next again it will be picked up from the connection pool.

Alsvha
November 16th, 2009, 04:42 AM
Even with connection pooling, there's a performance benefit in keeping a connection open manually if you need to do a lot of work over a short time.

However in the scenario outlined in the OP I would never, ever, advice keeping the connection open for that long, because you can quickly run out of connections, and it is very difficult in knowing when the user logs out. What if the user just closes the browser but does not select "log out" for example? Then you'll in theory never know he's logged out, and it's still consuming a connection.

So - in this case, I'd agree with Shuja Ali above and let the connection pool handle it. Just use care in how many and when you call the database.