将此文件存为xxingconn.asp (连接Access文件)
<%dim conn
dim connstr
call conn_init()
sub conn_init()
'on error resume next
'关键这里把Exam.mdb设为ip+文件如:132.146.11.24/test/Exam.mdb. test为虚拟目录
connstr = "DBQ=" + server.mappath("Exam.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
'response.write connstr
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
end sub
sub endConn()
conn.close
set conn=nothing
end sub
%>
调用xxingconn.asp
set rs=server.createobject("adodb.recordset")
'写Sql
SQL = "Select * From record where boardid="+cstr(bid)+" and stdname='"+pname+"'"
'打开通道
RS.Open SQL,conn,1,3