Use ASP Include Files for Database Connectivity

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 connObjSet 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 connObjSet 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:


Whenever you need to refer to a database connection object, such as in theOpen method of the recordset object, simply use objConn, the name of the connection object in databaseConn.asp.

See also  How to Avoid Money Transfer Scams  

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist