Keep Database Connection Open

J

Jim Mitchell

I store my connect string in the viewstate and open and close the SQL
database in every function or sub-routine call. Is there a better method of
opening the database when the ASPX page opens and cleanly closing it when
the page exits? I guess the on open part is easy, but how do I know that
the page closes so that I can be sure to close out the database connection?

What happens if I do a server.transfer from any of the pages? Do I have to
be careful and make sure the database connection is closed first? It seems
to me that some code does not execute if it is right before a
server.transfer?

Thanks in advance.

Jim
 
P

Paul Clement

¤ I store my connect string in the viewstate and open and close the SQL
¤ database in every function or sub-routine call. Is there a better method of
¤ opening the database when the ASPX page opens and cleanly closing it when
¤ the page exits? I guess the on open part is easy, but how do I know that
¤ the page closes so that I can be sure to close out the database connection?
¤
¤ What happens if I do a server.transfer from any of the pages? Do I have to
¤ be careful and make sure the database connection is closed first? It seems
¤ to me that some code does not execute if it is right before a
¤ server.transfer?

By definition every ASP page is stateless, with respect to object instances, after it has rendered.
You should open and close your connections during the processing of the page. If you don't
explicitly close a connection it isn't returned to the connection pool (if supported) immediately
for reuse and the connection object simply awaits garbage collection.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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

Top