This section provides a tutorial example on how to connect ASP script pages to an MS Access database directly without using ODBC.
Here is what I did to test those steps described in the previous section:
I ran MS Access. Created a blank database file called: "hello.mdb". Then created a table called "message"
in the database. In the "message" table, I added one field called "text".
Before closing the database file, I inserted one row in the "message" table with "Hello world!".
Then I copied "hello.mdb" to my local IIS server as "c:\inetpub\wwwroot\cgi-bin\hello.mdb".
My ASP script for this test was very simple, hello_access.asp:
<script language="vbscript" runat="server">
' hello_access.asp
' Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/cgi-bin/hello.mdb")
Set oRes = oConn.Execute("SELECT * FROM message")
Response.write(oRes("text"))
oRes.close
oConn.close
</script>
This script was also copied to my local IIS server as "c:\inetpub\wwwroot\hello_access.asp".
Then I opened Internet Explorer with http://localhost/hello_access.asp. I got:
Hello world!
Working, right?
Notes on this test:
The database driver "Microsoft.Jet.OLEDB.4.0" is smart to know how to talk to a MS Access database.
Server.MapPath() is used to convert a Web server path name to a Windows harddisk path name.
I did not use any loop structure on the result object. Only the first row is retrieved from
the result object.