<%
option explicit
dim conn, dbname
set conn = nothing
dbname = "db.asp"
dim maintain '维护
maintain = false
sub openconn
'on error resume next
if maintain then
set conn = createobject("adodb.connection")
'conn.connectionstring = "Driver={Microsoft Access Driver (*.mdb) };dbq=" & server.MapPath(dbname)
conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(dbname)
conn.open
if err.number>0 then
set conn = nothing
response.write "数据库错误"
response.end
end if
if isobject(application("conn")) then
application.Lock
set application("conn") = nothing
application.UnLock
end if
else
dim isobj
if isobject(application("conn")) then
if not application("conn") is nothing then
set conn = application("conn")
isobj = true
else
isobj = false
end if
else
isobj = false
end if
if not isobj then
set conn = createobject("adodb.connection")
'conn.connectionstring = "Driver={Microsoft Access Driver (*.mdb) };dbq=" & server.MapPath(dbname)
conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(dbname)
conn.open
if err.number>0 then
set conn = nothing
response.write "数据库错误"
response.end
end if
application.lock
set application("conn") = conn
application.unlock
end if
end if
end sub
openconn
sub closeconn
if not maintain then
exit sub
end if
if not conn is nothing then
conn.close
set conn = nothing
end if
end sub
%>