ASP Database support
• Introduction
• Checking objects
• Copying databases
• Creating databases
• Database connections
• Database browser
|
|
Putting a database-driven website on CD
|
Do you need to update the database with new information?
Unless you are , you will
not be able to directly update a database on a read-only CD. You will need to
either copy the database to the user's hard disk or
.
Copying a database from the CD to the user's hard disk.
To copy a database from the CD to the user's hard disk, use
Scripting.FileSystemObject.CopyFile. We suggest you use
the Windows Temporary Directory to store your database,
inform the user that your script will be making this copy, and ask whether they want the
database deleted after use. The copied database will be read-only and so the file attribute
will need to be re-set to make the database updateable :
To copy a database from the CD, follow these steps :
- check that the
Scripting.FileSystemObject
exists on the system
- check that the database to be copied exists
- check that the path to the destination database exists
- check that the destination database doesn't exist
- if the destination database exists and you decide to overwrite it, delete the destination database
- copy the database file
- fix the read-only attribute so that the database can be updated
<!-- include support functions -->
<!-- #INCLUDE FILE="adodbfns.asp" -->
<%
' -----------------
FUNCTION copyCDfile( srcFile, destFile, oWriteIfDestExists)
copyCDfile = FALSE
' is the FileSystemObject installed?
checkFSO
' is the source file there?
debugMsg( "Checking existence of " + srcFile)
IF NOT fso.FileExists( srcFile) THEN
Response.Write( "<BR>Can't find source file " + srcFile)
EXIT FUNCTION
ELSE
debugMsg( " - OK ")
END IF
' check the path to the destination file exists
' first get the path (assume there's a slash!)
slashAt = InStrRev( destFile, "\")
IF slashAt > 0 THEN
destPath = mid( destFile, 1, slashAt-1)
END IF
IF NOT fso.FolderExists( destPath) THEN
debugMsg( "Impossible destination path - " + destPath)
EXIT FUNCTION
END IF
' does the destination file exist already?
IF fso.FileExists( destFile) then
debugMsg( "File " + destFile + " exists already")
' if exists - decide what to do
IF oWriteIfDestExists THEN
fso.DeleteFile( destFile)
debugMsg( "Deleted file " + destFile)
ELSE
EXIT FUNCTION
END IF
ELSE
debugMsg( "File " + destFile + " doesn't exist")
END IF
' copy the file
fso.GetFile( srcFile).Copy destFile
' fix read-only attribute of copied file
Set myFile = fso.GetFile( destFile)
IF myFile.attributes AND 1 THEN
myFile.attributes = myFile.attributes - 1
debugMsg( "File " + destFile + " was readOnly - fixed")
END IF
debugMsg( "Copied " + srcFile + " => " + destFile)
copyCDfile = TRUE
END FUNCTION
' ------------------------
' RUN THE SCRIPT
' ------------------------
On error resume next
srcFile = "c:\test\test.mdb"
destFile = Request.ServerVariables( "WINDOWS_TEMP_DIR") &_
"\test.mdb"
dontDebug = FALSE
rval = copyCDfile( srcFile, destFile, TRUE)
Response.Write "<BR>copyCDfile " &_
IIF( rval, "succeeded", "failed")
%>
|
© Copyright 2000-2007
PHD Computer Consultants Ltd
|