View Full Version : <% ASP Database Connection %>

08-01-2003, 10:26 PM
Iíve been going to sites and I canít find out when to close my database connections

This is my connection
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("database.mdb")
MyConn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"


and here is closing

Now here is the question:
Do I close it on the bottom of every page or where?, because all the sites I go to say to ďclose it when you have finished with the databaseĒ

Itís for my personal e-mail home site

Any ideas??

09-01-2003, 06:01 AM

dbconn.Close tells the DataReader and database connection after access to the database is no longer required, and therefore closes the connection. So you only need it on pages that you use to access your database.


Heather P
09-01-2003, 07:58 AM
Site contains a number of pages - in this example pages A to G.

Pages A, F, G - html only, no database access so don't close.

Pages B, C, D, E - all require database access. Open it at the top of each of these pages and close it at the end of each of these pages.

Also, suggest you make one file for the database connection and use INCLUDE on each of the relevant pages. (Makes it easy to change the path if needed - one place only).

09-01-2003, 09:51 AM
OK so at the bottom of each asp page that uses MDB

and i am useing #includes