Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: All
Jan 14, 2000

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 %>
<HTML>
<BODY>
<%
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") & "<BR>"
 RS.movenext
wend
set conn=Nothing
set RS=Nothing
%>
</BODY>
</HTML>
Ken Cox
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap