Use Server.MapPath in database connection strings

Dreamweaver UltraDev is no longer supported, and the Dreamweaver UltraDev support center will no longer be actively updated. The functionality available in Dreamweaver UltraDev is available in Dreamweaver, beginning with Dreamweaver MX. Accordingly, we are moving pertinent content to the Dreamweaver support center. Please refer to the Dreamweaver version of this technote: Using Server.MapPath in database connection strings (TechNote 19065).

The purpose of the MapPath method of ASPServer object is to translate the logical path information that might be used by a client browser, into a physical path on the server. Users often take advantage of this ASP feature when using OLEDB, and ODBC DSNless connection strings.

If you have a file based database remotely mounted on your server, you must know the full path to that database in order to use a literal database connection string. However, there will be times you want to access such a database, but won't be able to count on the file's physical path. To find a file's physical path, you can use the Server.MapPath method. Its only parameter is the file's virtual, or relative, path.

If the parameter you pass starts with either a forward slash or a backslash, Server.MapPath assumes you want the full physical path that maps to the full virtual path. If the path parameter doesn't start with any slash, thenServer.MapPath assumes you want the physical path in relation to the location of the calling ASP file. For database connection string purposes, the full physical path is required.

UltraDev 4 offers the capability to useServer.MapPath in database connection strings. The following examples illustrate acceptable syntax in such strings.

  • DSNless (ADO) Connection Strings
    • Standard Connection String: "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\inetpub\wwwroot\ud\asp\UltraDev.mdb"
    • MapPath Connection String: "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/ud/asp/UltraDev.mdb") & ";"
  • OLEDB Connection Strings
    • Standard Connection String: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ud\asp\UltraDev.mdb"
    • MapPath Connection String: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/ud/asp/UltraDev.mdb")

Using Driver on Application Server versus Local Machine (Windows)

When defining a Custom Connection String in UltraDev, you have the option of using a driver on the Application Server or on the Local Machine.

Note: This option is not available in the Macintosh version of UltraDev. All connections use the Application Server.

In the Windows version, you must select Using Driver on Application Server when utilizing theServer.MapPath approach.

When using the Server ASP object, it can only be invoked via a web and application server. This is the connection method used when Using Driver on Application Server is selected. Selecting Using Driver on Local Machine connects to the database directly via ODBC; the web server, and thus the ASP Application Server, are not invoked.

It is acceptable to select Using Driver on Application Server when the server resides on the same machine as UltraDev, as when using Personal Web Server.

Note: In UltraDev 4, there is no longer a "Run Time" and "Design Time" connection. If you must useServer.MapPath for your Run Time connection, the same connection string must also apply to your design environment.

The following image shows the dialog box used to define a Custom Connection String in UltraDev using Server.MapPath and one of the connection string examples displayed above.

Dialog box used to define a Custom Connection String in UltraDev


Get help faster and easier

New user?