PDA

View Full Version : Confused with Objects.


hughesmi
04-23-2004, 01:38 AM
Hi all - IIS is giving me an eror say:

Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
default.asp, line 18

Here is my code, can some please spot where I'm going wrong? I can not figure out why it's saying abject is closed.

<%
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("links.mdb")

'Create an ADO recordset object
Set rsReadpage = Server.CreateObject("ADODB.Recordset")


strSQL = "SELECT * FROM AdministrationUsers WHERE Username='"& strUsername &"'"


'-- check to see if the user has registered before

If rsReadpage.EOF Then

'If RecordSet.fields("Username")=strUsername Then
If RecordSet.fields("Username")= hughesmi Then

Response.Write("<FONT FACE='ARIAL' SIZE='2'><B>Sorry this email has already been registred, please try again</B></FONT>")

End If

End if

%>

<!-- HTML FORM -->
<html>

<head>
<script TYPE="text/javascript">
<!--hide

function checkPass()
{
if(document.login.firstname.value == false)
{
alert('Please Enter Your First Name')
login.firstname.focus()
return false;
}
if(document.login.lastname.value == false)
{
alert('Please Enter Your Last Name')
login.lastname.focus()
return false;
}
if(document.login.pwd.value == false)
{
alert('You Need to Enter a Password.')
login.pwd.focus()
return false;
}
if(document.login.pwd.value != document.login.password.value)
{
alert('Your Passwords Do Not Match')
return false;
}
else
{
return true;
}
}

//end hide -->
</script>
<title>Password Entry Page</title>
</head>
<body>



<form METHOD="POST" name="login" ACTION="NewReg.asp" onSubmit="return checkPass()">

<fieldset>
<legend><font size="2" face="Tahoma">New Registration</font></legend>

<div align="center">
<center>
<table border="0" cellspacing="0" cellpadding="2" height="131">
<tr>
<td height="9"><b><font face="Tahoma" size="2">First Name:</font></b></td>
<td height="9"> <font face="Tahoma" size="2"> <input NAME="firstname" size="20" style="text-transform: capitalize"> </font> </td>
</tr>
<tr>
<td height="12"><b><font face="Tahoma" size="2">Last Name:</font></b></td>
<td height="12"> <font face="Tahoma" size="2"> <input NAME="lastname" size="20" style="text-transform: capitalize"> </font> </td>
</tr>
<tr>
<td height="21"><b><font face="Tahoma" size="2">Your Username Is:</font></b></td>
<td height="21"><font face="Tahoma"><b><font size="2" face="Tahoma"></font></b></font> </td>
</tr>
<tr>
<td height="21"><b><font face="Tahoma" size="2">Enter a Password:</font></b></td>
<td height="21"><font face="Tahoma" size="2"><input TYPE="password" NAME="pwd" size="20"> </font> </td>
</tr>
<tr>
<td height="25"><b><font face="Tahoma" size="2">Re-type your Password:</font></b></td>
<td height="25"><font face="Tahoma" size="2"><input TYPE="password" NAME="password" size="20">&nbsp;</font> </td>
</tr>
<tr>
<td height="27"><font face="Tahoma" size="2"><input TYPE="reset" VALUE="Rest"></font></td>
<td height="27">
<p align="center"><font face="Tahoma" size="2"><input TYPE="submit" VALUE="Save Your Details."></font></p>
</td>
</tr>
</table>
</center>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
</fieldset>
</form>
<p align="center"></p>
<p align="center"><font size="2" face="Tahoma">&lt;&lt; <a href="default.asp">Back</a></font></p>

</html>

<%
'Reset server objects
rsReadpage.Close
Set rsReadpage = Nothing
Set adoCon = Nothing

%>

glenngv
04-23-2004, 03:59 AM
You created a recordset but you didn't open it.
Also, the checking for existing user is wrong.
See the modification in red text.

'Create an ADO recordset object
Set rsReadpage = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM AdministrationUsers WHERE Username='"& strUsername &"'"

rsReadpage.Open strSQL, adoCon

'-- check to see if the user has registered before

If Not rsReadpage.BOF and Not rsReadpage.EOF Then
...

If you're using a correct cursor type for your recordset, you can use the RecordCount property to check the number of records retrieved. Wrong cursor type makes RecordCount always return -1.

rsReadpage.Open strSQL, adoCon, 1, 1 'adOpenKeyset, adLockReadOnly (you can use this constant instead, if you include adovbs.inc)

If rsReadpage.RecordCount>0 Then
...

miranda
04-23-2004, 06:22 PM
instead of including adovbs.inc you can just add one of these two lines to the page before you have any asp code connecting to a database
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->

<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->

hughesmi
04-23-2004, 08:53 PM
Thanks for you help on the object problem I got it working just fine!

However, I do require a litle more help.

Please have a look a this.


<!--#INCLUDE file="username.asp"-->

<%


Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("../links.mdb")

Set rsReadpage = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM AdministrationUsers WHERE Username='"& strUsername &"'"



rsReadpage.Open strSQL, adoCon


'Check to see if the user is allowed


If Not rsReadpage.BOF and Not rsReadpage.EOF Then


If rsReadpage.fields("Username")= strUsername Then

Response.Write(" ")
'Response.Redirect "default.asp"
'Else
'Response.Write("<FONT FACE='ARIAL' SIZE='2'><B>Not Allowed</B></FONT>")

End If
End if
%>

I have the asp checking the database to see if the user exists. But what I'm struggling with is how to the if else part working to say yes or no to user if not found on the database.

glenngv
04-26-2004, 03:38 AM
If rsReadpage.fields("Username")=strUsername Then
Response.Write("Found.")
Else
Response.Write("Not found.")
End If

hughesmi
04-26-2004, 07:31 PM
:thumbsup: thanks for you help :thumbsup: