Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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")

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"

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.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date