问题
Hello I'm trying to connect to the oracle data source and seems like when i test the code its giving me an error. Also, I believe it might be my data source path is wrong. Is there way to check the data source path in oracle or any kind of way? Thanks
<!--INCLUDED FILE = reset_password.asp -->
<%
DIM strEmail
strEmail = Request.Form("email")
IF strEmail <> "" THEN
%>
<!--#INCLUDE VIRTUAL="/includes/connection.asp"-->
<!-- ************SQL CONNECTION INSERT HERE*********************-->
<!-- *******
Set objDB = Server.CreateObject("ADODB.Connection")
objDB.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=c:\mydatabase.mdb"
**** -->
conn.
<%
DIM objDB
objDB = "SELECT email_addr,medacist_password FROM medacist_user WHERE email_addr = '" & strEmail & "'"
Set objDB = Server.CreateObject("ADODB.Connection")
objDB.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE= mmsg; Persist Security Info=True; User ID=mmsg; Password=langa;"
IF objDB.EOF THEN
Response.Write "That email address was not found in our database. Please click Back on your browser and enter the email address you registered with."
ELSE
DIM strPassword
strPassword = objDB("medacist_password")
DIM mail, objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "example@yahoo.com"
objMail.Subject = "Your Password"
objMail.To = strEmail
objMail.Body = "Here is your login password: " & strEmail
objMail.Send
'Set objMail to nothing to destory the mail object'
Set objMail = nothing
Response.Write "Your password has been sent to your email address."
END IF
ELSE
Response.Write "Please click Back on your browser and enter the email address you registered with."
END IF
回答1:
MICROSOFT.JET.OLEDB.4.0 is the OLEDB provider for MS Access. You'll need either an ODBC or an OLEDB connection string for Oracle. See this page for options
http://www.connectionstrings.com/oracle/
After that you need a recordset object as kloarubeek suggests above. A very simple way to do this would be as follows.
DIM objDB, rs, rssql
Set objDB = Server.CreateObject("ADODB.Connection")
objDB.Open "[your connection string goes here]"
rssql = "SELECT email_addr,medacist_password FROM medacist_user WHERE email_addr = '" & strEmail & "'"
Set rs = objDB.Execute(rsSQL)
Also I notice you are using CDONTS to send emails. It's deprecated and you won't find it on current versions of IIS by default. Look at CDOSYS instead
http://www.w3schools.com/asp/asp_send_email.asp
Finally, I recommend this page for anyone learning Classic ASP. It explains how to get error messages which are more useful than the basic 500 internal server error page.
http://www.chestysoft.com/asp-error-messages.asp
Edit
An example of a password retrieval script using CDOSYS and a recordset.
NB The CDO configuration will depend on your smtp server. Application("conn") means that my actual connection string is in a file called global.asa. This page actually connects to a SQL Server db, but the code should work with Oracle
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If InStr(request.form("username"),"@") > 0 Then
Set objMail = Server.CreateObject("CDO.Message")
Set iConfg = Server.CreateObject("CDO.Configuration")
Set Flds = iConfg.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youremailusername"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "youremailpasword"
.Update
End With
objMail.Configuration = iConfg
objMail.To = CStr(request.form("username"))
objMail.From = "you@yourdomain.com"
objMail.Subject = "Your login details"
objMail.TextBody = "Your login details are as follows " & vbcrlf & vbcrlf
set conn = Server.CreateObject("ADODB.Connection")
conn.open Application("conn")
sql = "select ContactEmailAddress, ContactAffiliateUsername, ContactAffiliatePassword from Contacts where ContactEmailAddress ='" & request.form("username") & "'"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,3,1
If rs.bof And rs.eof Then
response.redirect("invalidemailpage.asp?invalidemail=2")
Else
objMail.To = RS("ContactEmailAddress")
objMail.TextBody = objMail.TextBody & "Username = " & RS("ContactAffiliateUsername") & ", Password = " & RS("ContactAffiliatePassword") & vbcrlf
End If
objMail.Send
Set objMail = Nothing
rs.close
set rs = nothing
conn.close
set conn = nothing
response.redirect("login.asp?sentpassword=1")
Else
response.redirect("invalidemailpage.asp?invalidemail=1")
End If
%>
回答2:
I update the code and try if work. And seems like result still the same error 500. I also add another asp file where user enter the email and click reset button direct to confirm.asp. What is wrong with my code.
<html>
<head>
<title> Reset Password</title>
</head>
<body>
<STYLE type="text/css">
BODY {
background: #B4D7EB url("https://www.medacist.com/images/pic_medacist_gradient.jpg");
background-attachment: fixed;
background-repeat: repeat-x;
background-attachment: scroll;
}
</STYLE>
<div align="center">
<table border="0" width="100" id="table1" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<table border="0" width="100%" id="table2" cellspacing="0" cellpadding="0">
<tr><td valign="top"><img border="0" src="https://www.medacist.com/images/pic_medacist_header.jpg"></td></tr>
<tr><td valign="top">
<table border="0" width="100%" id="table3" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" bgcolor="#BBD6E7"><a href="http://www.medacist.com/index.asp"><img border="0" src="https://www.medacist.com/images/pic_medacist_head_01.jpg"></a></td>
<td valign="top" bgcolor="#BBD6E7"><img border="0" src="https://www.medacist.com/images/pic_medacist_nav_08.jpg"></td>
</tr>
</table>
</td></tr>
<tr><td valign="top"><img border="0" src="https://www.medacist.com/images/pic_medacist_hrule_01.jpg"></td></tr>
<tr><td valign="top" bgcolor="#FFFFFF">
<table border="0" width="100%" id="table4" cellspacing="0" cellpadding="0">
<tr><td valign="top">
<table border="0" width="100%" id="table6" cellspacing="0" cellpadding="0">
<tr><td valign="top"><img border="0" src="https://www.medacist.com/images/pic_medacist_main_slogan.jpg"></td></tr>
<tr><td valign="top" >
<center>
<table class="table1" width="100%" id="table8" cellspacing="0" cellpadding="0">
</table>
<h1>Forgot Your Password?</h1>
<p>Please Enter Your Email. <br>
<!-- *************************************************BUTTON CSS *********************************************************-->
<style type="text/css">
#submit {
-moz-box-shadow:inset 0px 1px 0px 0px #efdcfb;
-webkit-box-shadow:inset 0px 1px 0px 0px #efdcfb;
box-shadow:inset 0px 1px 0px 0px #efdcfb;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #dfbdfa), color-stop(1, #bc80ea));
background:-moz-linear-gradient(top, #dfbdfa 5%, #bc80ea 100%);
background:-webkit-linear-gradient(top, #dfbdfa 5%, #bc80ea 100%);
background:-o-linear-gradient(top, #dfbdfa 5%, #bc80ea 100%);
background:-ms-linear-gradient(top, #dfbdfa 5%, #bc80ea 100%);
background:linear-gradient(to bottom, #dfbdfa 5%, #bc80ea 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfbdfa', endColorstr='#bc80ea',GradientType=0);
background-color:#dfbdfa;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
border:1px solid #337bc4;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:arial;
font-size:14px;
font-weight:bold;
padding:4px 10px;
text-decoration:none;
text-shadow:0px 1px 0px #528ecc;
}
#submit:hover {
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff));
background:-moz-linear-gradient(top, #378de5 5%, #79bbff 100%);
background:-webkit-linear-gradient(top, #378de5 5%, #79bbff 100%);
background:-o-linear-gradient(top, #378de5 5%, #79bbff 100%);
background:-ms-linear-gradient(top, #378de5 5%, #79bbff 100%);
background:linear-gradient(to bottom, #378de5 5%, #79bbff 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#378de5', endColorstr='#79bbff',GradientType=0);
background-color:#378de5;
}
#submit:active {
position:relative;
top:1px;
}
</style>
<form name="email" action="confirm.asp" method="post">
<input type="email" name="email" size="30" required>
<input id="submit" type="submit" name="Submit" value="Reset">
</form>
</td></tr>
</table>
</center>
</td>
<td valign="top" background="images/pic_medacist_vrule_sp2.jpg" width="1"><img border="0" src="https://www.medacist.com/images/pic_medacist_vrule_02.jpg" width="7" height="667"></td>
</tr>
</table>
</td>
</tr>
<tr><td id="footer" valign="top">
<style type="text/css">
#footer{
background-repeat: no-repeat;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
background-image: url("../images/footer.gif");
font-size: 11px;
font-weight: bold;
height: 35px;
width: 650px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<span id="copyrightMessage">© 1997 - 2015, Medacist Solutions Group, LLC. All rights reserved. U.S. Patent No. 6,842,736 entitled 'Drug Auditing Method and System'.
<br /> </span>
</td></tr>
</table>
</td>
</tr>
<tr><td valign="top"><img border="0" src="https://www.medacist.com/images/0_ghost.gif" width="20" height="20"></td></tr>
</table>
</div>
</body>
</html>
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include virtual=reset_password.asp"-->
<html>
<head><title>Edit User Information</title></head>
<%
Dim oConn, oRs
Dim connectstr, sDSNDir, tablename
Dim db_name, db_username, db_userpassword
Dim dsn_name
dsn_name = "MySQL_TEST.dsn"
tablename = "medacist_user"
db_username = "chang"
db_userpassword = "PASSWORD123#"
sDSNDir = Server.MapPath("/_dsn")
connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Message
EmailFrom = "clu@medacist.com"
EmailTo = Trim(Request.Form("email"))
Subject = "Here is your Password"
Message = "You're password is:" & objRS("Password" )
Dim validationOK
validationOK=true
If (validationOK=false) Then Response.Redirect("index.html")
Dim Body
Body = Body & message
Dim mail
Set mail = Server.CreateObject("CDOSYS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send
Dim objRS, bolFound, strEmail
strEmail = Request.Form("email")
If strEmail = "" Then
oConn.Close
Set oConn = Nothing
Response.Write "<a href='reset_password.asp'>"
Response.Write "You must enter a email address"
Response.Write "</a>"
Response.End
End If
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "medacist_user", oConn, , , adCmdTable
bolFound = False
Do While Not (objRS.EOF OR bolFound)
If (StrComp(objRS("email"), strEmail, vbTextCompare) = 0) Then
BolFound = True
Else
objRS.MoveNext
End If
Loop
If Not bolFound Then
objRS.Close
Set objRS = Nothing
oConn.Close
Set oConn = Nothing
Response.Write "<a href='reset_password.asp'>"
Response.Write "Invalid Email Address.<p>"
Response.Write "</a>"
Response.End
End If
Dim objRS, bolFound, strEmail
strEmail = Request.Form("email")
If strEmail = "" Then
oConn.Close
Set oConn = Nothing
Response.Write "<a href='reset_password.asp'>"
Response.Write "You must enter a email address"
Response.Write "</a>"
Response.End
End If
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "medacist_user", oConn, , , adCmdTable
bolFound = False
Do While Not (objRS.EOF OR bolFound)
If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
BolFound = True
Else
objRS.MoveNext
End If
Loop
If Not bolFound Then
objRS.Close
Set objRS = Nothing
oConn.Close
Set oConn = Nothing
Response.Write "<a href='reset_password.asp'>"
Response.Write "Invalid Email Address.<p>"
Response.Write "</a>"
Response.End
End If
%>
</body>
</html>
来源:https://stackoverflow.com/questions/27748706/asp-classic-connection-string-500-internal-server-error