473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4064
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jabailo | last post by:
I created a web method to insert data on a DB2 database. It runs well, except every time I call it, it opens and closes the ADO connection. I think it would run faster, since I send it...
13
by: Larry | last post by:
Hi I have asp.net programs. I used a very simple data transfer method by using URLs ˇ°First.aspxˇ± contents a line to send data to the ˇ°second.aspxˇ± page, for
11
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a...
14
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same...
1
by: Jim Mitchell | last post by:
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...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
6
by: TheSteph | last post by:
Hi, (using C#, VS2005, .NET 2.0.) I sometimes need to access my database (SQL Server) in SINGLE_USER mode.
5
by: vieraci | last post by:
Hi, I'm wanting to start a database connection at the start of an app and keep it open for all methods and classes that I'm #including in my project. First I went about it by creating the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.