Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making connections....

Status
Not open for further replies.

JediBMC

MIS
Dec 5, 2003
178
US
I have serveral (OK, LOTS!) of pages that draw their content from databases. On these pages, the databases may be accessed one or more times. Is it better to close the connection each time a chunk of code is executed and then re-open it for the next chunk or is it better just to open once and leave it until the end?

-Brian-
I'm not an actor, but I play one on TV.
 
Standard good programming methods say yes. Open the conneciton and when the connection has been used and the process is completed, Close the connection until it is needed again by some event in need of a process.

 
If you are going to make several trips to the database in a row without some long delay between then I say keep the connection open.
For instance:
Open connect
Query1.Execute
Query2.Execute
Query3.Execute
Close connect

If your program sits and waits for a long or unpredictable amount of time before proceeding to the next DB event then close the connection and open it again when needed.



Stamp out, eliminate and abolish redundancy!
 
create functions and make it a include file...

and include this file on all your asp pages and call the function that sets the connection string and opens it at the top once and then call another function that closes all the connection and recordset objects at the end once...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top