Skip to content Skip to sidebar Skip to footer

Properly Closing A Database Connection - Vbscript + Ms Sql

I have a classic ASP (vbscript) web app that connect to an SQL server. On certain pages, I open multiple DB connections to pull data. My question is: Is it better to add a close c

Solution 1:

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:

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

Solution 2:

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.

Post a Comment for "Properly Closing A Database Connection - Vbscript + Ms Sql"