Solved

ADODB.Field error '80020009'

Posted on 2004-10-04
3
289 Views
Last Modified: 2012-05-05
I am trying to figure out why I continue to receive the above error when working with an ASP Login script. The core goal is to offer a graceful denial as opposed to obtaining the above error. I know the script works for valid username/ password combinations. However, when entering an invalid combination I receive the above error. My code is below:

<%
' Global Variables
Dim strEmail, strPassword, KeepChecking
Dim strStatus, strMessage, strRedirect, strSQL, rsUser

strStatus = Request("FormStatus")
strEmail = Replace(Request("txtEmail"),"'","`")
strPassword = Replace(Request("txtPassword"),"'","`")
strRedirect = Session("Redirect")

' Check to see if Login form was submitted or if a cookie exists
If strStatus = "Check" Or (Request.Cookies("Agency")("SignedIn") = "True" And Session("Authenticated") = 0) Then

      ' Validate the user
      If (Request.Cookies("Agency")("SignedIn") = "True") And (Request.Cookies("Agency")("Email") <> "") Then
            strSQL = "SELECT UserID, Email, Password, FirstName, LastName, SupervisorID, FK_AgencyID FROM Agency_Users WHERE (Email = '" & Request.Cookies("Agency")("Email") & "')"
      Else
            strSQL = "SELECT UserID, Email, Password, FirstName, LastName, SupervisorID, FK_AgencyID FROM Agency_Users WHERE (Email = '" & strEmail & "') AND (Password = '" & strPassword & "')"
      End If
      'Response.Write(strSQL)
      Set rsUser = conn_Agency.Execute(strSQL)

      If rsUser.EOF AND rsUser.BOF Then
            Session("Authenticated") = 0
            Response.Cookies ("Agency")("Email") = ""
            Response.Cookies ("Agency")("SignedIn") = "False"
            Response.Cookies ("Agency").Expires = DATE + 90
            KeepChecking = "No"
      Else
            KeepChecking = "Yes"
      End If
      
      If Request.Cookies("Agency")("SignedIn") <> "True" Then
            If strPassword <> rsUser("Password") Then
                  Session("Authenticated") = 0
                  Response.Cookies ("Agency")("Email") = ""
                  Response.Cookies ("Agency")("SignedIn") = "False"
                  Response.Cookies ("Agency").Expires = DATE + 90
                  KeepChecking = "No"
                  strMessage = "Invalid Password"
            Else
                  KeepChecking = "Yes"
            End If
      End If
      
      If KeepChecking = "Yes" Then
            Session("Email") = rsUser("Email")
            Session("Password") = rsUser("Password")
            Session("UserID") = rsUser("UserID")
            Session("UserName") = rsUser("FirstName") & " " & rsUser("LastName")
            Session("SupervisorID") = rsUser("SupervisorID")
            Session("AgencyID") = rsUser("FK_AgencyID")
            Session("Authenticated") = 1

            If Request("chkRemember") = "True" Then
                  Response.Cookies("Agency")("Email") = rsUser("Email")
                  Response.Cookies("Agency")("SignedIn") = "True"
                  Response.Cookies("Agency").Expires = DATE + 90
            End If
            
            conn_Agency.Close
            Set conn_Agency = Nothing

            Response.Redirect(strRedirect)
      End If
      
      conn_Agency.Close
      Set conn_Agency = Nothing
      Response.Redirect("default.asp")
End If
%>
0
Comment
Question by:Leo_Nel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Expert Comment

by:appari
ID: 12223535
try changing

     If Request.Cookies("Agency")("SignedIn") <> "True" Then
          If strPassword <> rsUser("Password") Then
               Session("Authenticated") = 0
               Response.Cookies ("Agency")("Email") = ""
               Response.Cookies ("Agency")("SignedIn") = "False"
               Response.Cookies ("Agency").Expires = DATE + 90
               KeepChecking = "No"
               strMessage = "Invalid Password"
          Else
               KeepChecking = "Yes"
          End If
     End If

with

     If Request.Cookies("Agency")("SignedIn") <> "True" Then
          if KeepChecking = "Yes" then           ' Added by me
          If strPassword <> rsUser("Password") Then
               Session("Authenticated") = 0
               Response.Cookies ("Agency")("Email") = ""
               Response.Cookies ("Agency")("SignedIn") = "False"
               Response.Cookies ("Agency").Expires = DATE + 90
               KeepChecking = "No"
               strMessage = "Invalid Password"
          Else
               KeepChecking = "Yes"
          End If
          end if         ' Added by me
     End If
0
 
LVL 12

Accepted Solution

by:
kingsfan76 earned 500 total points
ID: 12223551
here's the problem with this section of your code:
----------------
If Request.Cookies("Agency")("SignedIn") <> "True" Then
         If strPassword <> rsUser("Password") Then
              Session("Authenticated") = 0
              Response.Cookies ("Agency")("Email") = ""
              Response.Cookies ("Agency")("SignedIn") = "False"
              Response.Cookies ("Agency").Expires = DATE + 90
              KeepChecking = "No"
              strMessage = "Invalid Password"
         Else
              KeepChecking = "Yes"
         End If
    End If
------------------
>> If strPassword <> rsUser("Password") Then
if they are not equal, you'll never have a recordset in the first place (EOF).
so when you try to reference rsUser("Password") without having a recordset (password does not match), system will throw you an error.

i try not to change too much of your code, so here's a small fix that you might try:

<%
' Global Variables
Dim strEmail, strPassword, KeepChecking
Dim strStatus, strMessage, strRedirect, strSQL, rsUser

strStatus = Request("FormStatus")
strEmail = Replace(Request("txtEmail"),"'","`")
strPassword = Replace(Request("txtPassword"),"'","`")
strRedirect = Session("Redirect")

' Check to see if Login form was submitted or if a cookie exists
If strStatus = "Check" Or (Request.Cookies("Agency")("SignedIn") = "True" And Session("Authenticated") = 0) Then
    ' Validate the user
    If (Request.Cookies("Agency")("SignedIn") = "True") And (Request.Cookies("Agency")("Email") <> "") Then
         strSQL = "SELECT UserID, Email, Password, FirstName, LastName, SupervisorID, FK_AgencyID FROM Agency_Users WHERE (Email = '" & Request.Cookies("Agency")("Email") & "')"
    Else
         strSQL = "SELECT UserID, Email, Password, FirstName, LastName, SupervisorID, FK_AgencyID FROM Agency_Users WHERE (Email = '" & strEmail & "') AND (Password = '" & strPassword & "')"
    End If
    'Response.Write(strSQL)
    Set rsUser = conn_Agency.Execute(strSQL)

    If rsUser.EOF AND rsUser.BOF Then
         Session("Authenticated") = 0
         Response.Cookies ("Agency")("Email") = ""
         Response.Cookies ("Agency")("SignedIn") = "False"
         Response.Cookies ("Agency").Expires = DATE + 90
         KeepChecking = "No"
         if Request.Cookies("Agency")("SignedIn") <> "True" then
              strMessage = "Invalid Password"
         end if
    Else
         Session("Email") = rsUser("Email")
         Session("Password") = rsUser("Password")
         Session("UserID") = rsUser("UserID")
         Session("UserName") = rsUser("FirstName") & " " & rsUser("LastName")
         Session("SupervisorID") = rsUser("SupervisorID")
         Session("AgencyID") = rsUser("FK_AgencyID")
         Session("Authenticated") = 1

         If Request("chkRemember") = "True" Then
              Response.Cookies("Agency")("Email") = rsUser("Email")
              Response.Cookies("Agency")("SignedIn") = "True"
              Response.Cookies("Agency").Expires = DATE + 90
         End If
         
         conn_Agency.Close
         Set conn_Agency = Nothing

         Response.Redirect(strRedirect)
    End If
   
    conn_Agency.Close
    Set conn_Agency = Nothing
    Response.Redirect("default.asp")
End If

%>

p.s. it seems you want to print the strMessage for incorrect password, but i don't see where you want to print the message from your codes.   I believe if password is incorrect, then the page will redirect user to "default.asp".

0
 
LVL 15

Expert Comment

by:gladxml
ID: 12223789
Or you can also try this...

Happy programming...

replace this lines of code...  

    If rsUser.EOF AND rsUser.BOF Then
          Session("Authenticated") = 0
          Response.Cookies ("Agency")("Email") = ""
          Response.Cookies ("Agency")("SignedIn") = "False"
          Response.Cookies ("Agency").Expires = DATE + 90
          KeepChecking = "No"
     Else
          KeepChecking = "Yes"
     End If
     
     If Request.Cookies("Agency")("SignedIn") <> "True" Then
          If strPassword <> rsUser("Password") Then
               Session("Authenticated") = 0
               Response.Cookies ("Agency")("Email") = ""
               Response.Cookies ("Agency")("SignedIn") = "False"
               Response.Cookies ("Agency").Expires = DATE + 90
               KeepChecking = "No"
               strMessage = "Invalid Password"
          Else
               KeepChecking = "Yes"
          End If
     End If
 
with this

If rsUser.EOF AND rsUser.BOF Then
          Session("Authenticated") = 0
          Response.Cookies ("Agency")("Email") = ""
          Response.Cookies ("Agency")("SignedIn") = "False"
          Response.Cookies ("Agency").Expires = DATE + 90
          KeepChecking = "No"
     Else
            If Request.Cookies("Agency")("SignedIn") <> "True" Then
          If strPassword <> rsUser("Password") Then
               Session("Authenticated") = 0
               Response.Cookies ("Agency")("Email") = ""
               Response.Cookies ("Agency")("SignedIn") = "False"
               Response.Cookies ("Agency").Expires = DATE + 90
               KeepChecking = "No"
               strMessage = "Invalid Password"
          Else
               KeepChecking = "Yes"
          End If
              End If
     End If
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question