Properly closing a database connection - VBScript + MS SQL

Keep your connections open for as short a time as possible. Connection pooling will worry about efficiency for you.

But, if you have sequential db operations, they can share the same connection. This will also allow you to use transactions.


You should open one connection and make all queries at the top of your page then close the connection as soon as the last query has executed

Example:

Dim DBread
Set DBread = Server.CreateObject("ADODB.Connection")
DBread.Mode = adModeRead
DBread.Open (SQL_DB_CONN)

'Make SQL Calls Here and Save rows of data by using the getrows function

DBread.Close
Set DBread = Nothing

'Process rows of data here