Solved

ADODB.Field error '80020009'

Posted on 2004-10-04
3
283 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now