APPL_PHYSICAL_PATH Server Variable on Windows Vista RTM

By Robert McMurray

February 19, 2009

The original release of IIS 7.0 that shipped with Windows Vista returned a different value for the APPL_PHYSICAL_PATH server variable than that which was returned by previous or subsequent versions of IIS. In earlier versions of IIS, this server variable had a backslash "\" character appended to the path, but in the original release version of Windows Vista this server variable contained only the path. This was fixed in Windows Vista Service Pack 1 (SP1) and in the original release version of Windows Server 2008.

This means that if you are a Classic ASP developer and you are using the value in the APPL_PHYSICAL_PATH server variable to compute paths on the original release version of Windows Vista, your ASP code will have to account for the missing backslash character before migrating that application to another computer.

For example, the following ASP code computes the location of a Microsoft Access database in the App_Data folder of the current application:

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Request.ServerVariables("APPL_PHYSICAL_PATH") & _
"App_Data\example.mdb"
Set objCN = Server.CreateObject("ADODB.Connection")
objCN.Open strCN

If you were testing this code on a Windows XP computer that used IIS 5.1, this code would have worked successfully. However, if you upgraded your computer to the original release version of Windows Vista, the path of the database would be invalid and the connection to the database would fail. For example, if the ASP code was in a page in the root folder of the Default Web Site, the contents of the computed connection string might resemble the following:

DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\inetpub\wwwrootApp_Data\example.mdb

If you have ASP configured to send errors to the browser, you will see the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005' 

[Microsoft][ODBC Microsoft Access Driver] Disk or network error.

/example.asp, line 100

To resolve this issue for Windows Vista, you can install Windows Vista SP1, or you can have your ASP code manually check for the backslash character and add the backslash if it is required. For example:

strAP = Request.ServerVariables("APPL_PHYSICAL_PATH")
If Right(strAP,1)<>"\" Then strAP = strAP & "\"
strCN = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & strAP & "App_Data\example.mdb"

Set objCN = Server.CreateObject("ADODB.Connection")
objCN.Open strCN

More Information

For more information about IIS server variables, see the following page on the Microsoft MSDN Web site:

IIS Server Variables
http://msdn.microsoft.com/en-us/library/ms524602.aspx



Discuss in IIS Forums