Solved

ADODB.Field error '80020009'

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding items to html ul from on server side. 4 55
Time/Date Query 11 37
Select distinct 25 83
ASP Focus problem 3 53
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

14 Experts available now in Live!

Get 1:1 Help Now