ASP+MSSQL 读取140条记录,花费8秒时间,哭啊!求救!

hanfeng4827 2012-08-04 03:18:26

求各位大侠帮帮忙,看看是哪里出问题。 其实就是个列表页面读取出问题了。

好像内容还发不上来,

<%
option explicit
dim startime
dim connstr,conn
dim db,pass_word,User_ID,Data_Source
startime=timer()
db="guoanwuliu" '数据库名称
Pass_word="sa" 'Password=帐号密码
User_ID="sa" 'User ID=登陆帐号
Data_Source="(local)" 'Data Source=服务名称或者ip

Set conn = Server.CreateObject("ADODB.Connection")
connStr="Provider=SQLOLEDB.1;Password='"&pass_word&"';Persist Security Info=True;User ID='"&User_ID&"';Initial Catalog='"&db&"';Data Source='"&Data_Source&"'"
conn.Open connstr
function CloseConn()
Conn.close
Set conn = Nothing
End Function
%>


这个是数据库连接方法。连接正常
MSSQL ,我是采用以前ACCESS的方法,直接建立数据库,然后也是右键,新建表,把ID作为主键,没做其他操作,再说也不会啊。
请各位大侠指教,

源码 http:www.qhsteel.com/guoan_wl.rar 总共440K
数据库 在里面的 .bak 文件 登陆名 和密码 aaa aaa
我的Q 259137882,哪位大侠帮帮忙吧!拜托了!
...全文
200 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
兼哲 2012-08-05
  • 打赏
  • 举报
回复
这代码看着真心凌乱啊
Junhong_c 2012-08-05
  • 打赏
  • 举报
回复
尽可能试着把各个查询语句集起来查询,没必要一直开关数据库,而且还在循环嵌套。
Junhong_c 2012-08-05
  • 打赏
  • 举报
回复
你可以分段调试看看在运行哪一段时速度比较慢,还有就是建议读取数据时要有开有关。
ChinaXtHuLang 2012-08-04
  • 打赏
  • 举报
回复
还原了。没有看到你说的清楚。你就3张表。3张表里面没有一张表有140条数据啊。
hanfeng4827 2012-08-04
  • 打赏
  • 举报
回复
额………… BAK的还原不是很简单吗~~~~~
我的数据库也是2005的
对象资源管理器中,右键数据库,还原数据库

目标数据库随便写
点原设备,找到BAK文件,打开后要打钩,

点左上角的 选项 覆盖现有数据。 就OK了
ChinaXtHuLang 2012-08-04
  • 打赏
  • 举报
回复
下载了。我用SQL2005还原失败。不弄了。你自己弄吧。
.bak还原不会..
hanfeng4827 2012-08-04
  • 打赏
  • 举报
回复
<%@language=vbscript codepage=936 %>
<!--#include file="inc/conn.asp"-->
<!--#include file="quanx.asp"-->
<%
dim sql,rs,sqla,rsa,wangdian,id,KaiDan,HD
dim i,HDnum,YJnun,JSnum,XFmoney,SHmoney,ALLmoney,DaoZhan,TXF
if session("username")="" or session("Purview")<15 then
ErrMsg=ErrMsg & "<li>您没有权限操作,请联系管理员!</li>"
call WriteErrMsg()
response.end
end if
%>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<body >
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="17" valign="top" height="29" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
<td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
<tr>
<td width="100" height="31"><div class="titlebt1">发货单管理</div></td>
<td width="142" > </td>
<td >本页显示收货站点未收到货的运单,若已到达收货站点,则不在本页显示,可点击左侧的“运单状态”查看。</td>
</tr>
</table></td>
<td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
</tr>
<tr>
<td valign="middle" background="images/mail_leftbg.gif"> </td>
<td valign="top" bgcolor="#F7F8F9">

<table width="100%" border="1" bordercolor="#CCCCCC" cellpadding="0" cellspacing="0" class="line_table" >
<tr >
<td width="3%" height="27" align="center" background="images/news-title-bg.gif" ><strong>ID</strong></td>
<td width="7%" height="27" align="center" background="images/news-title-bg.gif" ><strong>运单号</strong></td>
<td width="7%" align="center" background="images/news-title-bg.gif" ><select name="daozhan" id="daozhan" onChange="location.href=this.options[this.selectedIndex].value;">
<option selected>到站</option>

<%
set rs=server.CreateObject("adodb.recordset")
sql="select DISTINCT DaoZhan from yundan where FaZhan ="& session("wangdian") &" and HWDZ=0 "
rs.open sql,conn,1,3
if not rs.eof and not rs.bof then
do while not rs.eof
set rsa=server.CreateObject("adodb.recordset")
sqla="select * from wangdian where id="&rs("DaoZhan")&" "
rsa.open sqla,conn,1,3
if not rsa.eof then
DaoZhan=rsa("wangdian")
else
wangdian="数据错误"
end if
%>
<option value="W_guanli_yundan.asp?action=shaixuan&DaoZhanid=<%=rs("DaoZhan")%>" ><%=DaoZhan%></option>
<%
rs.movenext
loop
end if
%></select></td>
<td width="16%" height="27" align="center" background="images/news-title-bg.gif" ><strong>发货单位</strong></td>
<td width="8%" height="27" align="center" background="images/news-title-bg.gif" ><strong>电话</strong></td>
<td width="6%" height="27" align="center" background="images/news-title-bg.gif" ><strong>件数</strong></td>
<td width="7%" align="center" background="images/news-title-bg.gif" ><strong>提/现付</strong></td>
<td width="7%" align="center" background="images/news-title-bg.gif" ><strong>代收</strong></td>
<td width="6%" align="center" background="images/news-title-bg.gif" ><strong>送货费</strong></td>
<td width="6%" align="center" background="images/news-title-bg.gif" ><strong>月结</strong></td>
<td width="6%" align="center" background="images/news-title-bg.gif" ><strong>签回单</strong></td>
<td width="6%" align="center" background="images/news-title-bg.gif" ><strong>经办人</strong></td>
<td width="7%" align="center" background="images/news-title-bg.gif" ><strong>日期</strong></td>
<td width="8%" align="center" background="images/news-title-bg.gif" ><strong>操作</strong></td>
</tr>
<!----------------开始循环输出记录------------------------------------------------------------------------------->
<%
set rs=server.CreateObject("adodb.recordset")
if request("action")<>"" then
sql="select * from yundan where FaZhan ="& session("wangdian") &" and HWDZ=0 and DaoZhan="&request("DaoZhanid")&" order by ADDdatetime desc"
else
sql="select * from yundan where FaZhan ="& session("wangdian") &" and HWDZ=0 order by ADDdatetime desc"
end if
rs.open sql,conn,1,3
i=0
HDnum=0
YJnun=0
JSnum=0
XFmoney=0
SHmoney=0
ALLmoney=0
%>
<% if rs.eof and rs.bof then%>
<tr>
<td height="27" colspan="14" align="center">系统未读取到满足条件的数据,有可能是您选择有误,或是系统中还没有数据!</td>
</tr>
<%
else
do while not rs.eof
id=rs("id")
set rsa=server.CreateObject("adodb.recordset")' 判断到站名称
sqla="select * from wangdian where id="&rs("DaoZhan")&" "
rsa.open sqla,conn,1,3
if not rsa.eof then
wangdian=rsa("wangdian")
else
wangdian="数据错误"
end if
''''''''''''''''''''''''''''''''''''''''''''''''判断经办人姓名
set rsa=server.CreateObject("adodb.recordset")
sqla="select * from admin where id="&rs("KaiDan")&" "
rsa.open sqla,conn,1,3
if not rsa.eof then
KaiDan=rsa("xingming")
else
wangdian="数据错误"
end if

if i mod 2 =0 then
%>
<tr bgcolor="#f2f2f2" onmouseover= "this.style.background= '#FF0 ';this.style.color= '#F60 ' " onmouseout= "this.style.background= '#f2f2f2 ';this.style.color= '#000 ' ">
<td height="27" align="center" ><%=i+1%></td>
<td align="center" ><%=trim(rs("YDnumber"))%></td>
<td align="center" ><%=wangdian%></td>
<td align="center" ><%=trim(rs("FaDanWei"))%></td>
<td align="center" ><%=trim(rs("FaDianhua"))%></td>
<td align="center" ><%=trim(rs("JianShu"))%></td>
<td align="center" >
<%
IF rs("TiFu")<>"" then
TXF="提¥" &rs("TiFu")
end if
if rs("XianFu")<>"" then
TXF="现¥" &rs("XianFu")
end if
%>
<%=TXF%></td>
<td align="center" ><%=trim(rs("DaiShou"))%></td>
<td align="center" ><%=trim(rs("SongHuo"))%></td>
<td align="center" ><%=trim(rs("YueJieJE"))%></td>
<td align="center" >
<%
if trim(rs("HuiDan"))=1 then
HD="是"
ELSE
HD=""
end if
%><%=HD%></td>
<td align="center" ><%=KaiDan%></td>
<td align="center" ><%=month(rs("ADDdatetime"))&"月"&day(rs("ADDdatetime"))&"日"%></td>
<td align="center" >
<%if trim(rs("HWDZ"))=1 then
%>
修改 删除
<%else%>
<a href="W_modi_yundan.asp?action=modi&id=<%=rs("id")%>">修改</a> <a href="W_DEL_yundan.asp?action=DEL&id=<%=rs("id")%>&danhao=<%=trim(rs("YDnumber"))%>">删除</a></td>
<%end if%>
</tr>
<%else%>
<tr onmouseover= "this.style.background= '#FF0 ';this.style.color= '#F60 ' " onmouseout= "this.style.background= '#ffffff ';this.style.color= '#000 ' ">
<td height="27" align="center" ><%=i+1%></td>
<td align="center" ><%=trim(rs("YDnumber"))%></td>
<td align="center" ><%=wangdian%></td>
<td align="center" ><%=trim(rs("FaDanWei"))%></td>
<td align="center" ><%=trim(rs("FaDianhua"))%></td>
<td align="center" ><%=trim(rs("JianShu"))%></td>
<td align="center" >
<%
IF rs("TiFu")<>"" then
TXF="提¥" &rs("TiFu")
end if
if rs("XianFu")<>"" then
TXF="现¥" &rs("XianFu")
end if
%>
<%=TXF%></td>
<td align="center" ><%=trim(rs("DaiShou"))%></td>
<td align="center" ><%=trim(rs("SongHuo"))%></td>
<td align="center" ><%=trim(rs("YueJieJE"))%></td>
<td align="center" >
<%
if trim(rs("HuiDan"))=0 then
HD=""
else
HD="是"
end if
%><%=HD%></td>
<td align="center" ><%=KaiDan%></td>
<td align="center" ><%=month(rs("ADDdatetime"))&"月"&day(rs("ADDdatetime"))&"日"%></td>
<td align="center" >
<%if trim(rs("HWDZ"))=1 then
%>
修改 删除
<%else%>
<a href="W_modi_yundan.asp?action=modi&id=<%=rs("id")%>">修改</a> <a href="W_DEL_yundan.asp?action=DEL&id=<%=rs("id")%>&danhao=<%=trim(rs("YDnumber"))%>">删除</a></td>
<%end if%>
</tr> <%
end if
i=i+1
TXF=NULL
HD=Null
if trim(rs("HuiDan"))=1 then '回单总数
HDnum=HDnum+1
end if
if trim(rs("yuejie"))=1 then '月结总数
YJnun=YJnun+1
end if
if rs("JianShu")<>"" then '总件数
JSnum=JSnum+ int(rs("JianShu"))
end if
if trim(rs("yuejie"))<>1 and rs("XianFu")<>""then '现付总额
XFmoney=XFmoney+rs("XianFu")
end if
if trim(rs("yuejie"))<>1 and rs("SongHuo")<>""then '送货费总额
SHmoney=SHmoney+rs("SongHuo")
end if
ALLmoney=XFmoney+SHmoney
rs.movenext
loop
rs.close
set rs=nothing
end if
%>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="10" ></td>
</tr>
<tr>
<td height="27" align="center" class="zhongdian">共<strong> <%=i%> </strong>条运单信息;<strong><%=HDnum%> </strong>张回单;月结客户<strong> <%=HDnum%></strong> 单;总件数<strong> <%=JSnum%> </strong>;应付到站网点:现付¥<strong> <%=XFmoney%> </strong>元,送货费¥<strong> <%=SHmoney%> </strong>元,总共¥<strong> <%=ALLmoney%> </strong>元。</td>
</tr>
</table></td>
<td background="images/mail_rightbg.gif"> </td>
</tr>
<tr>
<td valign="bottom" height="17px" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="16" /></td>
<td height="17px" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17"></td>
<td height="17px" valign="bottom" background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
</tr>
<tr><td height="10px"></td></tr>
</table>
</body>
hanfeng4827 2012-08-04
  • 打赏
  • 举报
回复
那我在换一个地址 vhost1343804958000.yun01.yhosts.com/guoan_wl.rar 总共440K
数据库 在里面的 .bak 文件 登陆名 和密码 aaa aaa
ChinaXtHuLang 2012-08-04
  • 打赏
  • 举报
回复
下载了半个小时的没有下载下来。
Junhong_c 2012-08-04
  • 打赏
  • 举报
回复
不如把代码放上来让大家看看
hanfeng4827 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

数据库大了吧,有没有分区,索引。
[/Quote]
不大,总共不到500条记录。3个表,其中两个,每个最多20条,另外一个做测试,写了400多条,读取速度要8秒以上,
tsjit 2012-08-04
  • 打赏
  • 举报
回复
数据库大了吧,有没有分区,索引。
ChinaXtHuLang 2012-08-04
  • 打赏
  • 举报
回复
不会慢啊。我刚把数据加到了:280。直接一刷的就出来了。
AMinfo 2012-08-04
  • 打赏
  • 举报
回复
你要把读记录的代码发上来,速度快慢跟连接的代码是没什么关系的。

决定快慢的前提条件就是硬件环境,比如说网站服务器与数据库服务器之前的通讯速度,如果本身通讯速度慢的话,那就是代码再好也不可能快。

如果硬件环境本身是很快的,那就要发代码上来,检查代码。
hanfeng4827 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

还原了。没有看到你说的清楚。你就3张表。3张表里面没有一张表有140条数据啊。
[/Quote]
哦,我后来添加了一些记录在里面,你点击左侧的“发货单管理” 就知道了,慢是要死。要8秒才能读出清单来。

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧