水兰花有毒吗:有段asp连接sql数据库的程序,可是连接非常慢,请高手看看怎么回事?

来源:百度文库 编辑:高考问答 时间:2024/04/28 21:49:44
<%set rs=server.createobject("adodb.recordset")
rs.open "select * from SMT_sca where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
scacount=rs.recordcount
rs.close
rs.open "select * from SMT_cp where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
cpcount=rs.recordcount
rs.close
rs.open "select * from SMT_job_zp where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
zpcount=rs.recordcount
rs.close
rs.open "select * from SMT_job_qz where SMT_key=1 and SMT_key1=1 and SMT_key2=1 and SMT_iname is not null",conn,1,1
qzcount=rs.recordcount
rs.close
rs.open "select * from SMT_yp where SMT_key<>0 and SMT_key<>2 and SMT_key1=1",conn,1,1
ypcount=rs.recordcount
rs.close
rs.open "select * from SMT_exhibit where SMT_key<>0 and SMT_key2=1",conn,1,1
zhcount=rs.recordcount
rs.close
rs.open "select * from SMT_xxnews where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
newscount=rs.recordcount
rs.close
rs.open "select * from SMT_news where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
newscount=rs.recordcount+newscount
rs.close
set rs=nothing%>

如果你只是想查询记录数量的话不要这么查,应该使用
select count(*) from tablesname where ***
-----
rs.open "select * from SMT_sca where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1
改为====
rs.open "select count(*) from SMT_sca where SMT_key=1 and SMT_key1=1 and SMT_key2=1",conn,1,1

同时
scacount=rs.recordcount
改为===
scacount=rs(0)

这样可以避免把所有数据都传输到内存中,只要一条记录一个字段就可以了。

连续读取这么多数据,建这么多数据加接,不慢才怪。

哈哈其实这个问题很简单,就是每操作打开关闭一次数据库,就会浪费一下时间,你看看你的这个程序,到处都是这个玩意,不慢才怪!