怪,如果连接字符串设错了,照样能显示登录成功,为何,见代码:
怪,如果连接字符串设错了,照样能显示登录成功,为何,见代码:
我试了,如果在连接函数中有on error resume next,则连接串错时,打开记录集还有记录,真怪了。
当然如果去了on error resume next,则会在浏览器中报错。我就是不明白,就是忽略错误,也无法取到记录集呀?我是用rs.recordcount判断的。现把用到的两个asp文件贴出来,大家指教一下。
我的连接函数如下:
文件名为:generaltools.asp
<!-- VB Script Document -->
<%
dim conn,weburl,strconn
'weburl="http://" & request.servervariables("server_name") & "/"
on error resume next
strconn = "driver={sql server};"
strconn = strconn & "server=(local);"
strconn = strconn & "database=fjfj;"
strconn = strconn & "uid=sa;"
strconn = strconn & "pwd=0000"
sub openconn()
set conn = server.createobject("adodb.connection")
conn.open strconn
end sub
sub closeconn()
if isobject(conn) then
conn.close
set conn = nothing
end if
end sub
%>
----------------------------------------------------
我的验证表单文件:
<!-- #include file = "generaltools.asp"-->
<html>
<head>
<title>登陆</title>
</head>
<body>
<div align center>
<%
dim strusername
dim strpassword
dim rs
dim sql
'response.write "ok" & "<br>"
strusername = request.form("txtusername") '用户名
strpassword = request.form("txtpassword") '密码
if strusername = "" then
'response.redirect "ghindex.htm"
end if
if strpassword = "" then
'response.redirect "ghindex.htm"
end if
if len(strusername) > 10 then
response.write "用户名太长"
'response.redirect "ghindex.htm"
end if
if len(strpassword) > 6 then
response.write "密码太长"
'response.redirect "ghindex.htm"
end if
'连接串:
call openconn '调连接函数
set rs=server.createobject("adodb.recordset")
sql = "select 编号,姓名,密码 from zgma where 编号 = '" & strusername & "' and 密码 = '" & strpassword & "'"
'response.write sql
rs.open sql, conn,1,1
if rs.recordcount <> 0 then
session("username")= strusername
response.write "登录成功!" & "<br>" ////连接串设错了,这一句也会执行
response.write "你的姓名是:" & rs("姓名") & "<br>"
else
response.write "登录不成功!" & "<br>"
response.write "no" & "<br>"
end if
rs.close
set rs=nothing
call closeconn
%>
</div>
</body>
</html>