How to set up a file Data Source Name -- Sample Code
Here are the sample code blocks and directions needed to set up a "File DSN" to make your web portable:
[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
ReadOnly=0
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=MS Access
DriverId=25
<%
' set up variables
Dim sDB, sPath, sDSNDir, sDSNFil, sDefDir, sDSN, sScriptDir
' The variable sDB contains the database path.
' It is physical with respect to your
' main project or web directory. In
' other words, it assumes that you
' have the subdirectory "fpdb" beneath
' your web directory and that your Access
' database file (named mydatabase.mdb) was
' imported into that directory.
'
sDB = "fpdb\mydatabase.mdb"
' Retrieve the script directory of this currently executing file
sScriptDir = Request.ServerVariables("SCRIPT_NAME")
sScriptDir = StrReverse(sScriptDir)
sScriptDir = Mid(sScriptDir, InStr(1, sScriptDir, "/"))
sScriptDir = StrReverse(sScriptDir)
' Set the virtual Directory
sPath = Server.MapPath(sScriptDir) & "\"
' This is the DSN file Name for Access database ODBC general specs
sDSNFil = "msaccess.dsn"
' Build the resulting DSN string SDSN which can then be used in the .Open method
sDSN = "filedsn=" & sPath & sDSNFil & ";DefaultDir=" & sPath & ";DBQ=" & sPath & sDB & ";"
%>
<%@ LANGUAGE="VBSCRIPT" %>
<!-- #include file="DSN.asp" -->
set myConn=Server.CreateObject("ADODB.Connection")
myConn.Open sDSN
This approach makes your entire application portable from one web server to
another.