Where to open connection and close it ?

S

Saulot

Hi,
Facing a big problem.
In my Default.aspx page, I open a connection with ma Sql Server DataBase
through my objects framework (A "SetDefaultConnectionString" property which
open my connection... work fine with winforms)
My Default.aspx page is a login one.
When I log in, no problem, I got my
Response.Redirect("DefaultEmployee.aspx") which works well. Then, I click on
another Redirect which leads me to the employee's personnal informations and
THERE, Problem.
BUT, using spy window, I can see that just after the Redirect thing, my
connectionstring is set to nothing !!!

So here is the point.
Is there a place to open my connection that it'll be available for the whole
pages of my site and so on, a place to close it when my user lives the site.
I tried Application_start and didn't work.

Help please.
 
K

Karl Seguin

Saulot:
You are supposed to open connections as late as possible and close them as
soon as possible. You are totally trying to do the opposite.

Also, you provided no code and no information about the actual
problem/error/exception.

OPen the connection, fill your dataset, close the connection, return the
dataset...

Karl
 
P

Patrice

In a web application, the page is recreated each time (if you keep the
connection string in a page member it will be reinitialized the next time as
the page just lives the time of the HTTP request).

Also you generally open/create the connection each time you need it to avoid
:
- having a unique connection for all users (it would block users majking
this single connection a bottleneck)
- haing a connection for each user (it would use a vast amount of resources)

ASP.NET uses a connection pool. When you create a connection, it is taken
from the pool. When you close it, it is returned to the pool. This way you
only need as much connections, as you have current requests executing (ie.
you could server 100 users with 10 connections).

Patrice
 
M

Mark Rae

Is there a place to open my connection that it'll be available for the
whole
pages of my site and so on, a place to close it when my user lives the
site.

I'm struggling to think of anything worse than this for completely crippling
your site's performance!!!
 
I

Ian Frawley

Maybe if it queries a table that returns thousands of results and then binds
them server side to a datagrid without paging. That would be a start.
 
M

Mark Rae

Maybe if it queries a table that returns thousands of results and then
binds
them server side to a datagrid without paging. That would be a start.

LOL! Maybe if it then downloads the resultset of this query to each client's
PC for "really efficient" client-server architecture ;-) Could just query it
locally, no need for that costly round-trip to the server any more...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top