I use a Function call inside my config.inc file to attach to my database. First I'll show you the function call I created and then how it's called from inside my application. You should also use create a CloseDB to properly destroy all the objects created when your through. Here's the OpenDB function call.Function OpenDB (ByRef Cn)
Set Cn = Server.CreateObject("ADODB.Connection")
With Cn
.ConnectionString = DSNLess
.ConnectionTimeout = 180
.Open
End With
The ConnectionTimeout sets a length of time that the program will work to make a connection. The higher the number, the longer the time. 180 is a good average time for most connections. If you start to receive ODBC errors because of the amount of data in your database you may want to try adjusting this time.
Your first step in retrieving data or inserting data into your database is to create the connection. You call the function call by creating an instance of the connection. See Below.
OpenDB Cn
Cn represents the connection object.
The CloseDB function call closes all the database objects and destroys them from memory. If you don't close the objects and destroy them, you will eventually use us the memory on the server causing it to lock up. As a developer it's your responsibility to insure you destroy all instances. Below is an example of a CloseDB function call.
Function CloseDB()
Cn.Close
Set Cn = Nothing
End Function
This is called from within the program as shown below.
CloseDB
Back |