1.创建一个myconn.ini文件。(myconn.ini存于data/myconn.ini,
数据库存于data/mydata.mdb)
2.在调用文件中包含myconn.ini
myconn.ini文件:
<%
dim myconn,connstr
connstr="DBQ="+server.mappath("data/mydata.mdb")+ _
";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" + _
"DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;" + _
"MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;" + _
" SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
set myconn=server.createobject("ADODB.CONNECTION")
myconn.connectiontimeout=20
myconn.open connstr
%>
调用文件view.asp:
<% option explicit%>
<!-- #include file="data/myconn.inc" -->
<html>
....
<body>
<%
dim rs
dim sql
set rs=server.createobject("adodb.recordset")
sql="select * from guestbook"
rs.open sql,myconn,1,1
%>
...
</body>
</html>