File DSN's

Sunday Jan 24th 1999 by ServerWatch Staff

Have you ever had the need to set up a new Database, but dont have the rights to set up a system DSN?

by Bob Dombroski

Have you ever had the need to set up a new Database, but dont have the rights to set up a system DSN? You could set up a connection string in a application variable, but on any change you would need to cycle the server(and if you dont have rights to set up a system DSN, you probably wont have rights to cycle the server). How about setting up a file DSN? Its quick, painless and can be easily changed.

The best part of using a file dsn, you can create an entire new application on a local machine accessing a local database, then move it to a remote server and install the database right from your local machine without involving an administrator. This can save the developer valuable time.

The working examples of my articles on hit counters and database based forms both use file DSN's for connecting to a database.

Steps to create a file DSN source.(This example will connects to an Access Database)

Open up a text editor and create a file named WEB.DSN
Type in the following:
DRIVER=Microsoft Access Driver (*.mdb)
FIL=MS Access

Save this file in the root directory of your web application. Notice that I dont give the default drive and DBQ within the actual file DSN, this is so that I can reuse the DSN for every Access DB which  I need a connection to.

To use the file DSN is as simple as building a connection string giving the file DSN name and building the database source.

'First create the connection object
Set oconnect = Server.CreateObject("ADODB.Connection")

'Next I map a path to a virtual directory containing all my databases
'This saves time moving the application from a local to a remote server, the
'Physical paths can change, but the virtaul remain the same. Server.MapPath returns
'A physical path from a virtual directory.

'Next build a connection string using the file DSN we created and
'The mapped path to the database directory with the database we want to connect to

                 "DBQ=" & DB_PATH & "\WEBDB.MDB;"

'Now connect as normal and your done
oconnect.Open CONNECT_STR

That's all there is to it!

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved