[thelist] Friday's Freebie, part II

Scott Dexter sgd at ti3.com
Fri Apr 7 17:58:51 2000


<tip type="ASP" title="simplifying db connection setup and teardown"
author="youknowwho">
these two little ditties save me a ton of typing. Because you are supposed
to be opening and closing DB connections *AS SOON AS POSSIBLE*, these get
used a lot.

... you are opening and closing the db connection as soon as possible,
right?

Function SetupSQL(byval connstr)
Dim DBCON
Set DBCON = Server.CreateObject("ADODB.Connection")
DBCON.ConnectionTimeout = 15
DBCON.CommandTimeout = 15
DBCON.Open connstr
Set SetupSQL = DBCON
Set DBCON = Nothing
End Function

use:

Set myDBCON = SetupSQL("DSN=northwind;UID=sa;PWD=123xyzmom;")

Sub CloseSQL(byref DBCON)
DBCON.Close
Set DBCON = Nothing
end sub

use:

CloseSQL myDBCON

ĦBonus! you can use the CloseSQL() subroutine for recordset objects too
</tip>

sgd
--
think safely