Database connection

06-17-2002, 10:07 AM
I'm really new to ASP, but I understand and use ADO connections to Access databases. In my reading, I keep seeing info regarding a file that holds the database path called a .inc file. What exactly is this file supposed to contain? An example would reallllly help! I can upload a database to the web server, right? So, that brings me to the next question... What is the ADO connection path supposed to look like from the web host?


Derek Stone
06-17-2002, 01:54 PM
Using an include file (*.inc) is completely optional, however it IS good practice to do so. Using such a file lets you to centralize your connection strings and global variables in one place, allowing for easy modifications in the future.

The complete contents of an include file ( could look like this:

Option Explicit

Dim sMainDatabase, sSecondaryDatabase, sBackupDatabase

sMainDatabase = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\main_database.mdb;"
sSecondaryDatabase = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\secondary_database.mdb;"
sBackupDatabase = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\backup_database.mdb;"

Here's an Active Server Page that uses the include file:

<!--#INCLUDE FILE="" -->

<!--#INCLUDE FILE="" -->

Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sMainDatabase
Conn.Execute "INSERT INTO myTable (User, Password) VALUES('Bill', '12345')
Set Conn = Nothing

<!--#INCLUDE FILE="" -->

At some point the location of your database might change, and one easy update to will take care of it. Or, you may upgrade to a MySQL database and you'll need to modify the connection string to reflect the changes. The benefits of using an include file you ask? If you had several pages similar to the one above that one change would save you a significant amount of tedious work.

Good Luck

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum