Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADODB.Field error '80020009'

Posted on 2004-10-04
3
Medium Priority
?
292 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 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