奇怪的问题~~~~~全部的分都给了~~~

myufo1234 2009-08-05 05:39:34
昨天我接手修改一Asp+Accessr的网站
在后台登录的地方出现一奇怪的问题:


用户名和密码判断页面 Login.asp
<!--#include file="../Inc/Conn.asp" -->
<html>
<head>
<title></title>
</head>
<body>
<%
Session.TimeOut=30
username=trim(request.form("name"))
pwd=trim(request.form("pwd"))
if username="" or pwd="" then
Response.Redirect ("Login.asp")
end if
set rs=server.createobject("adodb.recordset")
sql = "select * from user_admin where UserName='"&username&"' and Pwd='"&pwd&"'"
rs.open sql,conn,1,1
'=======
if not rs.eof then '此处不管用户名密码是否正确,甚至查询一个数据库中不存在的表都为真,
session("name")=username
response.redirect ("Manage.asp")else
Response.Redirect ("Loginsb.asp?msg=您输入了错误的帐号或口令,请再次输入!")
response.end
end if
%>
</body>
</html>
数据库连接文件 Conn.asp
<%
dim conn
dim connstr
db="数据库文件位置"
on error resume next
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db)
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
set conn = Nothing
response.write "数据库连接出错,请检查conn.asp中的连接字符串。"
response.end
end if

测试的时候提示 "数据库连接出错,请检查conn.asp中的连接字符串。" 这是在Conn.asp文件中,将该文件的
if err then 改为 if err.number>0 then时不再出错,但在Login.asp中的数据查询得不到任何结果,只要输入任何内容都可以登录到后台,因为 not rs.eof 永远为True,甚至在查询一个不存在的表时也没有报错 not rs.eof仍然为True ,估计是连接数方面的问题,但我对这方面不太了解,所以无法确定。而且以上的代码是经过测试的,所以代码方面应该也没有问题,连接文件整个网站共用这一个,其它地方也正常。也可排除权限的问题。此问题只在IIS上面出现,其它服务软件均正常。
只要问题解决马上结帖给分,如果结帖前还有可用分立即加分。

测试环境:windows server 2003、IIS 6.0
...全文
159 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsxnb 2009-08-06
  • 打赏
  • 举报
回复
10楼、11楼已经指出代码的问题,
刚好遇到 数据空记录,

应该把if not rs.eof then 改成

if (not rs.eof) And (not rs.bof) then
或 if not (rs.eof And rs.bof) then

myufo1234 2009-08-06
  • 打赏
  • 举报
回复
问题解决:
我觉得可能引发错误的地方就是路径,所以我就给它一绝对路径,结果它也很干脆直接报路径错误,找不到文件。
解决方法:
使用数据源连接、把IIS换成其它服务软件都OK。最后决定使用其它服务软件。


问题其实还没解决,但由于时间问题,结帖~~~~,

谢谢大家的回复~~~~~
jiangshanwws 2009-08-06
  • 打赏
  • 举报
回复
IIS 数据连接 都从新搞一下
搬运工865 2009-08-06
  • 打赏
  • 举报
回复
留个位置等奇怪的答案 看不出问题。。。
cpp2017 2009-08-06
  • 打赏
  • 举报
回复
是这个文件的代码有问题。所以要找到问题。
myufo1234 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 cpp2017 的回复:]
那就是了,因为你有错误。你的找到详细错误,你配置一下iis,将500错误指到iishelp/500-100.asp上。

如果你没有iishelp虚拟目录的话,建一个,指向windows\help\comm\iishelp目录。这样能显示详细错误。

[/Quote]

试试先~我还有一问题,我在同一目录下不同文件里包含同一个Conn.asp为什么只有这个文件是出错,其它都OK呢?
这个问题我从昨天搞到今天,头都大了,要是你这样的高手都没办法,我也不准备再改了,先用其它方法做好再说,以后有时间再改~~
myufo1234 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 hookee 的回复:]
注释on error resume next后不运行, 说明有错, 此时才能看到页面的错误信息
[/Quote]

有错是肯定的,要不就不会出问题了,我现在怀疑根本没有连接到数据库,但是我把路径什么的输出来又没有问题,把 if err then 改成 if err.number>0 then又不会报连接出错,我就奇怪,既然err.number=0那先前那个条件应该不会执行才对。到处都是看不明白的问题,也不知是谁写的程序,搞得乱七八糟的,头都大了,

还有这个问题只在IIS环境下才会有
cpp2017 2009-08-06
  • 打赏
  • 举报
回复
那就是了,因为你有错误。你的找到详细错误,你配置一下iis,将500错误指到iishelp/500-100.asp上。

如果你没有iishelp虚拟目录的话,建一个,指向windows\help\comm\iishelp目录。这样能显示详细错误。
myufo1234 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 cpp2017 的回复:]
我试过,注释掉这行根本不能运行~

什么叫不能运行?报什么错误?

[/Quote]

http 500
cpp2017 2009-08-06
  • 打赏
  • 举报
回复
我试过,注释掉这行根本不能运行~

什么叫不能运行?报什么错误?
hookee 2009-08-06
  • 打赏
  • 举报
回复
注释on error resume next后不运行, 说明有错, 此时才能看到页面的错误信息
myufo1234 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 cpp2017 的回复:]
把conn中和页面中

所有on error resume next  去注释掉,再看


我就不信你查一个不存在的报不出错.

[/Quote]

我试过,注释掉这行根本不能运行~
我输入的错误号,也就是err.number是0,也就是没有错。请注意这是在注释掉err.clear,的情况下输出的
invoked 2009-08-06
  • 打赏
  • 举报
回复
up
myufo1234 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 ilxl520 的回复:]
看看报什么错啊
[/Quote]

在没有err.clear的情况下输出err.number是0,也就是没有错也会执行这里~~
cpp2017 2009-08-06
  • 打赏
  • 举报
回复
把conn中和页面中

所有on error resume next 去注释掉,再看


我就不信你查一个不存在的报不出错.
ilxl520 2009-08-06
  • 打赏
  • 举报
回复
看看报什么错啊
myufo1234 2009-08-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hookee 的回复:]
没有 conn.open connstr?
VBScript code<!--#include file="../Inc/Conn.asp"--><html><head><title></title></head><body><%
Session.TimeOut=30
username=trim(request.form("name"))
pwd=trim(request.form("pwd"))if username=""or pwd=""then
Response.Redirect ("Login.asp")endif

conn.open connstr
username=Replace(username,"'","''")
pwd=Replace(pwd,"'","''")set rs=server.createobject("adodb.recordset")
sql="select * from user_admin where UserName='"&username&"' and Pwd='"&pwd&"'"
rs.open sql,conn,1,1'=======ifnot (rs.eofAnd rs.bof)then
session("name")=username
rs.close
conn.close
response.redirect ("Manage.asp")else
conn.close
Response.Redirect ("Loginsb.asp?msg=您输入了错误的帐号或口令,请再次输入!")
response.endendif
%>
[/Quote]

我少贴了一行~~程序中有~~谢谢
myufo1234 2009-08-05
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 tsxnb 的回复:]
if rs.bof and rs.eof then 
'是空记录集
else
'......
end if
[/Quote]

问题依旧~~
谢谢你的回复
myufo1234 2009-08-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 lzp4881 的回复:]
if not rs.eof then      '此处不管用户名密码是否正确,甚至查询一个数据库中不存在的表都为真,
session("name")=username
response.redirect ("Manage.asp")else 这里得换行啊
Response.Redirect ("Loginsb.asp?msg=您输入了错误的帐号或口令,请再次输入!")
response.end
end if

[/Quote]

程序中有换行
谢谢你的回复
hookee 2009-08-05
  • 打赏
  • 举报
回复
没有 conn.open connstr?

<!--#include file="../Inc/Conn.asp" -->
<html>
<head>
<title> </title>
</head>
<body>
<%
Session.TimeOut=30
username=trim(request.form("name"))
pwd=trim(request.form("pwd"))
if username="" or pwd="" then
Response.Redirect ("Login.asp")
end if

conn.open connstr
username = Replace(username,"'","''")
pwd= Replace(pwd,"'","''")

set rs=server.createobject("adodb.recordset")
sql = "select * from user_admin where UserName='"&username&"' and Pwd='"&pwd&"'"
rs.open sql,conn,1,1
'=======
if not (rs.eof And rs.bof) then
session("name")=username
rs.close
conn.close
response.redirect ("Manage.asp")
else
conn.close
Response.Redirect ("Loginsb.asp?msg=您输入了错误的帐号或口令,请再次输入!")
response.end
end if
%>
加载更多回复(10)

28,390

社区成员

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

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