Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Nov 17, 2001

Use ASP Include Files for Database Connectivity


To avoid repeating the following lines of code in every ASP page that needs a database connection:
 
{
Dim connObj
Set connObj = Server.CreateObject("ADODB.Connection")
connObj.ConnectionString = Session("ConnectionString")
connObj.Open
}

You can use an include file, which contains the above lines (and the connection string). Say you do this in a file named databaseConn.asp, and put it in your /scripts directory. databaseConn.asp might look something like this:
 
<%
Dim connObj
Set connObj = Server.CreateObject("ADODB.Connection")
connObj.ConnectionString = "DSN=Blah"
connObj.Open
%>

Then, in every page where you need database connectivity, you just need to add this one line:
 
<!--#include virtual="/scripts/databaseConn.asp"-->

Whenever you need to refer to a database connection object, such as in the Open method of the recordset object, simply use objConn, the name of the connection object in databaseConn.asp.
Sandeep Gain
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap