在asp重复打开connection会占有资源吗?

来源:百度知道 编辑:UC知道 时间:2024/07/06 15:56:04
我在conn.asp中正确定义了数据库的连接信息,并在该文件末加入了
cn.open来打开数据库,在其他网页中只通过include来包含这个文件实现数据库连接
问题:如果我在每个文件中加入cn.close来关闭数据库,那么每打开一个包含了conn.asp的网页是否意味着和数据库建立了一个连接??
我在网上下了一些源代码,发现他们也没有在网页的末尾加入cn.close
刚才的问题打错了,修改如下
问题:如果我在每个文件中加入conn.asp来打开数据库,那么每打开一个包含了conn.asp的网页是否意味着和数据库建立了一个连接??
我在网上下了一些源代码,发现他们也没有在网页的末尾加入cn.close

这样就不会了.

<%
if not isobject(DBConn) then
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.ConnectionTimeout = 15
DBConn.CommandTimeout = 30
DBConn.CursorLocation = 3

DBConn.Open "Provider=MSDASQL;Persist Security Info=False;Extended Properties=""DRIVER={Microsoft ODBC for Oracle};UID=cisprg;SERVER=;"";", "", ""
if not Response.IsClientConnected then
DBConn.Close()
set DBConn = nothing
response.end
end if
end if
%>

set cn =server.createobject("adodb.connection")
cn.open
对应的就是
cn.close
set cn = nothing

如果你及时使用了
cn.close
set cn = nothing
数据库的链接就及时销毁了。