Let ASP’s Server.MapPath Find Your Database

Let ASP’s Server.MapPath Find Your Database

When you use a “DSN-less” data connection to a Microsoft Access database, you must provide the physical path to the database. If your files are kept on your ISP’s Web server, you may have trouble keeping track of the disk drive and path. However, you can let Active Server Pages locate your database for you. Just hand the virtual directory name to the Server.MapPath() method and let it return the physical path. After that, concatenate the connection string as shown in the following ASP code. In the sample, /work_p450/ is the virtual directory and empemail.mdb is the database name.

 <%@ Language=VBScript %><%set conn=server.CreateObject("ADODB.Connection")conn.Open "driver={Microsoft Access Driver (*.mdb)};" & _ "dbq=" & Server.MapPath("/work_p450/empemail.mdb") & ";" & _ "uid=admin; pwd="set RS = conn.Execute( _	"SELECT * FROM Employees " _	& "ORDER BY LastName, FirstName")while not RS.eof Response.Write RS("LastName") & "
" RS.movenextwendset conn=Nothingset RS=Nothing%>
See also  Small Business Strategies with Venmo

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist