Using a virtual path to connect to a database

Using a virtual path to connect to a database

To write a DSN-less connection string to a database file located on a remote server, you must know the physical path to the file. For example, here is a typical DSN-less connection string for a Microsoft Access database:

Driver={Microsoft Access Driver (*.mdb)};
DBQ=c:\Inetpub\wwwroot\accounts\users\jsmith\data\statistics.mdb

If you don’t know the physical path of your files on the remote server, you can get the path by using the MapPath method in your connection string.

To create a DSN-less connection with the MapPath method:

  1. Upload the database file to the remote server.

    Make a note of its virtual path--for example, /jsmith/data/statistics.mdb.

  2. Open an ASP page in Dreamweaver, then open the Databases panel (Window > Databases).

    Dreamweaver displays all the connections defined for the site.

  3. Click the Plus (+) button on the panel and select Custom Connection String from the pop-up menu.
  4. Enter a name for the new connection.
  5. Enter the connection string and use the MapPath method to supply the DBQ parameter.

    Suppose the virtual path to your Microsoft Access database is /jsmith/data/statistics.mdb. The connection string can be expressed as follows if you use VBScript as your scripting language:

    "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath?
    ("/jsmith/data/statistics.mdb")
    

    The ampersand (&) is used to concatenate (combine) two strings. The first string is enclosed in quotation marks and the second is returned by the Server.MapPath expression. When the two strings are combined, the following string is created:

    Driver={Microsoft Access Driver (*.mdb)};
    DBQ=C:\Inetpub\wwwroot\accounts\users\jsmith\data\statistics.mdb
    

    If you use JavaScript, the expression is identical except that you use a Plus (+) sign instead of an ampersand (&) to concatenate the two strings:

    "Driver={Microsoft Access Driver (*.mdb)};DBQ=" + Server.MapPath?
    ("/jsmith/data/statistics.mdb")
    
  6. Select the Using Driver On Testing Server option.

    Macintosh users can ignore this step because all database connections use the application server.

  7. Click Test.

    Dreamweaver attempts to connect to the database. If the connection fails, double-check the connection string.

    If the connection still fails, contact your ISP to make sure the database driver you specified in the connection string is installed on the remote server. Also check that the ISP has the most recent version of the driver. For example, a database created in Microsoft Access 2000 will not work with Microsoft Access Driver 3.5. You need Microsoft Access Driver 4.0 or later.

  8. Click OK.

    The new connection appears in the Databases panel.

  9. Update the database connection of existing dynamic pages, and use the new connection with any new page you build.

    To update the connection of a dynamic page, open the page in Dreamweaver, double-click the recordset name in the Bindings panel or Server Behaviors panel, and select the connection you just created from the Connection pop-up menu.

Related topics

  • Understanding physical and virtual paths
  • Finding a file’s physical path with the virtual path
  • Creating a DSN-less connection


Getting Started with Dreamweaver
Dreamweaver Basics
Working with Dreamweaver Sites
Laying Out Pages
Adding Content to Pages
Working with Page Code
Preparing to Build Dynamic Sites
Making Pages Dynamic
Developing Applications Rapidly