|
|
 |
|
Lesson 20: DSN-less MS Access connection |
|
Lesson 20: DSN-less MS Access connection
Summary:
Learn to connect to an MS Access database with a DSN-less connection
Intro:
In lesson 17 I showed you have you created
an Access database and how you could connect to it with ASP
through ODBC using a DSN file. You need to have full access
to the server to create the DSN file, something that can be difficult if your
site is hosted somewhere. In this lesson I will teach you how to make a DSN-less
connection. And as tests has shown, an DSN-less connection to Access gives you better
performance! You can have up to 20-30 simultaneous users on the db without problems.
A regular DSN connection would not handle this kind of load.
(This is not the case for MS SQL Server). Check out this great Power ASP article to learn more.
The database
The database I'm going to use is the same as the one we
created in lesson 17. You can use that, or
download this small sample database I have made (68K).
The sample database viewed in Access
The connection
To display the content of the database we will use the same code
as in Lesson 17, except that we will change the MyConn.Open line:
<HTML>
<BODY>
<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("sample.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT * FROM Friends"
Set RS = MyConn.Execute(SQL_query)
WHILE NOT RS.EOF
%>
<LI><%=RS("Name")%>: <A HREF="<%=RS("Link")%>">Homepage</A>
<%
RS.MoveNext
WEND
%>
</BODY>
</HTML>
We connect to the Access database file directly through the Access driver.
All we have to do is specify the correct driver and to tell the driver where
the mdb file is. In this case the mdb file is called sample.mdb and is located
in the same folder as the script. Server.MapPath returns the mdb file's
physical path (e.g. c:\sample.mdb).
The output will look like this:
Arnstein: Homepage
Thomas: Homepage
Willy: Homepage
Where to go next:
Check out the other lessons.
| |
|
|
 |
|