469,599 Members | 2,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,599 developers. It's quick & easy.

Keep Database Connection Open

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
Jul 21 '05 #1
1 3924
On Tue, 7 Oct 2003 19:01:51 -0400, "Jim Mitchell" <ji**********@mindspring.com> wrote:

¤ 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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jabailo | last post: by
11 posts views Thread by pradeep_TP | last post: by
1 post views Thread by Jim Mitchell | last post: by
35 posts views Thread by Terry Jolly | last post: by
5 posts views Thread by Usman Jamil | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.