Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection in a function

Status
Not open for further replies.

sparky68

Programmer
Feb 27, 2002
11
0
0
US
It’s been suggested that I put the db connection lines into a function, then include that file on the pages its needed in. has anyone done this? I cant find and code examples on this anywhere.
 
put this in a file, and call it conn.asp

include it on any page by putting:

<!-- #include file=&quot;../path/conn.asp&quot; -->

MIGHT look like this (the entire file):
Code:
<%
dim con
set con = server.createObject(&quot;ADODB.Connection&quot;)
function openConnection()
  con.open connectionStringHere
end function
function closeConnection()
  con.close
end function
function destroyConnection()
  set con = nothing
end function
%>

then on any page you've included it on, just issue:

openConnection 'to open it
closeConnection 'to close it
destroyConnection 'to get rid of it

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top