You can use a DSN-less connection to create an ODBC or OLE DB connection between your web application and your database. You use a connection string to create this kind of connection.
If you’re an ASP developer working with a commercial Internet service provider (ISP), you often don’t know the physical path of the files you upload, including your database file or files.
If your ISP doesn’t define a DSN for you or is slow to do so, you must find another way to create the connections to your database files. One alternative is to create a DSN-less connection to a database file, but you can define such a connection only if you know the physical path of the database file on the ISP server.
You can obtain the physical path of a database file on a server by using the MapPath method of the ASP server object.
After using Dreamweaver to upload your files to a remote server, the files reside in a folder in the server’s local directory tree. For example, on a server running Microsoft IIS, the path to your home page could be as follows:
c:\Inetpub\wwwroot\accounts\users\jsmith\index.htm
This path is known as the physical path to your file.
The URL to open your file, however, does not use the physical path. It uses the name of the server or domain followed by a virtual path, as in the following example:
www.plutoserve.com/jsmith/index.htm
The virtual path, /jsmith/index.htm, stands in for the physical path, c:\Inetpub\wwwroot\accounts\users\jsmith\index.htm.
If you work with an ISP, you don’t always know the physical path to the files you upload. ISPs typically provide you with an FTP host, possibly a host directory, and a login name and password. ISPs also specify a URL to view your pages on the Internet, such as www.plutoserve.com/jsmith/.
If you know the URL, then you can get the file’s virtual path—it’s the path that follows the server or domain name in a URL. Once you know the virtual path, you can get the file’s physical path on the server using the MapPath method.
The MapPath method takes the virtual path as an argument and returns the file’s physical path and filename. Here’s the method’s syntax:
Server.MapPath("/virtualpath")
If a file’s virtual path is /jsmith/index.htm, then the following expression returns its physical path:
Server.MapPath("/jsmith/index.htm")
You can experiment with the MapPath method as follows.
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. The following example 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.