Dynamic-CD
Search : 
  Powered by FindinSite

ASP Database support
• Introduction
• Checking objects
• Copying databases
• Creating databases
• Database connections
• Database browser
    
Putting a database-driven website on CD

Making the connection to the database.
The most common problem in getting a database to work using Dynamic-CD is a faulty connection string.

The standard server connection string

<%
  connString = "dsn=myDatabase"
  SET con = Server.CreateObject( "ADODB.Connection")
  con.Open connString
%>
is for a DNS connection which needs to be set up in the registry of each computer that is to run your database. Clearly this is impossible for a database on CD. You need to set up a non-DNS connection string as follows.

To connect to the database, use the Microsoft Jet provider connection string. The path to the database should be detemined using the Server.MapPath method - rather than an absolute path - so that the path is correct for whatever CD drive is being used.

<%
  dbPath = Server.MapPath( "../databases/myDB.mdb")

  connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
  SET con = Server.CreateObject( "ADODB.Connection")
  con.Open connString + dbPath
%>

We recommend that all versions of MS-ACCESS database be converted to MS-ACCESS 2000. If you need to create an earlier database version, this can be done by adding the Engine Type to the connection string. ACCESS 97 is Engine Type=4, ACCESS 2000 is Engine Type=5.

If database is protected by a password, the password should be added to the connection string.

<%
  connString = _
  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
    dbPath &_
    ";Jet OLEDB:Database Password=" + userPwd &_
    ";Jet OLEDB:Engine Type=5;"
%>
Databases should not be password protected using the Dynamic-CD-Wizard - this would make them unreadable by the ADODB component. To protect databases, give them a database password using MS-ACCESS and then connect to them as above. The dbPwd itself can be hidden in an encrypted ASP file.

Managing source code for the Internet and for Dynamic-CD
To manage your source code, code specific to Dynamic-CD and code specific to your server can be stored in the same source and distiguished as follows :

<%
  IF Request.ServerVariables( "DYNCD_HOST") = "Dynamic-CD" THEN
    dbPath = Server.MapPath( "../databases/myDB.mdb")
  ELSE
    dbPath = "c:/inetpub/databases/myDB.mdb"
  END IF
%>

© Copyright 2000-2007 PHD Computer Consultants Ltd