File DSN's

Sunday Jan 24th 1999 by ServerWatch Staff
Share:

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:
[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
ReadOnly=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=MS Access
DriverId=25

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.
DB_PATH = SERVER.MAPPATH("/DATABASE")

'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

CONNECT_STR = "FILEDSN=WEB.DSN;" & _
                 "DBQ=" & DB_PATH & "\WEBDB.MDB;"

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

That's all there is to it!

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