求助 能否同时连接2个不同数据库
一个简单的登录验证页面,不知道哪里出错了。麻烦各位帮忙看一下con.asp
<%
Dim SqlDataName,SqlUserPassword,SqlUserName,SqlLocalName,ConnStr
SqlDataName="zpwang"
SqlUserPassword="sa"
SqlUserName="sa"
SqlLocalName="127.0.0.1"
ConnStr="Provider=Sqloledb;User ID="&SqlUserName&";PassWord="&SqlUserPassword&";Initial Catalog = " & SqlDataName & "; Data Source = " & SqlLocalName & ";"
Set Conn=server.CreateObject("ADODB.Connection")
Conn.open ConnStr
if Err Then
err.clear
set Conn=nothing
response.Write("数据库连接出错,请检查连接字串")
response.End
end if
Dim webflag,rs
Set rs=server.CreateObject("ADODB.Recordset")
rs.open "select * from aaaa",Conn,3,2
if rs.Eof or rs.Bof then
webflag=rs("webflag")
end if
rs.close
%>
conn2.asp
<%
Dim SqlDataName2,SqlUserPassword2,SqlUserName2,SqlLocalName2,ConnStr2
SqlDataName2="wywang"
SqlUserPassword2="wy"
SqlUserName2="wy"
SqlLocalName2="127.0.0.1"
ConnStr2="Provider=Sqloledb;User ID="&SqlUserName2&";PassWord="&SqlUserPassword2&";Initial Catalog = " & SqlDataName2 & "; Data Source = " & SqlLocalName2 & ";"
Set Conn2=server.CreateObject("ADODB.Connection")
Conn2.open ConnStr2
if Err Then
err.clear
set Conn2=nothing
response.Write("数据库连接出错,请检查连接字串")
response.End
end if
Dim webflag2,rs2
Set rs2=server.CreateObject("ADODB.Recordset")
rs2.open "select * from bbbb",Conn2,3,2
if rs2.Eof or rs2.Bof then
webflag2=rs2("webflag")
end if
rs2.close
%>
login.asp 这里代码没写全
<form action="login_check.asp" name="form1" method="post">
用户名:<input type="text" name="user" />
密码:<input type="password" name="pw"/>
<input type="submit" name="submit" value="登陆" />
</form>
login_check.asp
<!--#include file="Conn.asp"-->
<!--#include file="Conn2.asp"-->
<%
user=replace(request.Form("user"),"'","''")
pw=replace(request.Form("pw"),"'","''")
Dim wfg
if wfg=webflag then
Set Rs=server.CreateObject("ADODB.Recordset")
Dim sql
sql="select * from test where username='"&user&"' and password='"&pw&"'"
Rs.open sql,Conn,3,2
if Rs.Eof Then
response.Write("你好!!!")
response.Write "你输入的密码错误"
response.End
Else
response.Redirect"a.asp"
End if
else
if wfg=webflag2 then
Dim sql2
Set Rs2=server.CreateObject("ADODB.Recordset")
sql2="select * from test where username='"&user&"' and password='"&pw&"'"
Rs2.open sql2,Conn2,3,2
if Rs2.Eof Then
response.Write("我好")
response.Write "你输入的密码错误"
response.End
Else
response.Redirect"aaa.asp"
End if
End if
end if
%>
这里2个test表都是一样的
test
id username password
1 aaaa bbbb
test
id username password
1 aabb 1111
aaaa表
id webflag
1 0
bbbb表
id webflag
1 1
为什么连接不到第二个表的数据
我用username=aaaa password=bbbb时能显示跳转的那个页面(登陆成功) 我用 username=aabb password=1111时 提示 “你好!!!
你输入的密码错误"
[ 本帖最后由 ab382717036 于 2011-3-25 11:38 编辑 ]