Page uload occurs two times when redirecting

M

mortb

Hi,

I'm overriding OnUload in my pages. I've put the Connection.Close in the
method.
But I have noticed that the method is run twice if I do a Response.Redirect
in the page.
Do some one know why?

cheers,
mortb
 
B

Brock Allen

I'm not sure what your problem is; But I'd like to comment on your approach
to database connection management. I'd suggest not opening a connection early
and closing it late as it seems you're doing in the page. I'd suggest instead
opening it late and closing it early. IOW, open the connection right when
you need it, use it (get your data, update, whatever), then close it right
there and then (in your Page_Load or Button_Click or whereever). Connections
are pooled so in a miltiuser environment like ASP.NET you'll have good chances
of reusing open connections that have been put back into the pool.

Also, it helps to make sure that you never have any idle connections. If
you open the connection in Page_Load, say, and close it in Unload... well,
there are cycles where the connection is doing nothing, but it's allocated
and owned by your page an unusable to anyone else. So putting it back in
the pool ASAP let others use it and you end up using fewer connections at
the same time.

Lastly, opening late and closing early makes for less buggy code and less
chances for a leak of the connection.
 
J

Josh

Good Advice! I wonder if Mortb is an ex Windows Developer, they seem to
think like that?
 
M

MattC

Or better still implement your connection management in a seperate layer
that closes the connection after the command is executed and have nodb
management code in your Page_Load or Button_Click events :)

MattC
 
J

Josh

Or better still implement your connection management in a seperate layer
that closes the connection after the command is executed and have nodb
management code in your Page_Load or Button_Click events :)

I think OO is dead. The new thing is code in the UI!
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top