Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2004, 04:05 PM
Authorized User
 
Join Date: Feb 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in code

I am having the following error, but most of the solutions I got relates to the error when a stored procedure is used and 'am not using a stored procedure, so how do I correct it.
here's the error:
ADODB.Recordset error '800a0e78' The operation requested by the application is not allowed if the object is closed.



here's the code:
<% Response.Buffer = true %>



<html>
<head>
<Title>Passoword change website</title>
</head>
<body>
<h2>Password change response<h2>
<%

'Declare variable needed
Dim strSql
Dim adCmdText

adCmdText = 1

'Retrieve the values
varStudentID = Request.Form("StudentId")
varPassword = Request.Form("Password")
varNewpassword = Request.Form("NewPassword")


'start building sql statement
strSql = "Update Try Set"
strSql = strSql & " Password ='" & varNewpassword & "'"
strSql = strSql & " WHERE StudentID =" & varStudentID
strSql = strSql & " AND Password='" & varPassword & "'"

'Create and Open connection to database
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.OPen "DSN=new1"


'Create command object
Set objCmd = Server.CreateObject("ADODB.Command")

'Set Command Properties
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = strSql
objCmd.CommandType = adCmdText

'Execute Command
 set objRS = objCmd.Execute


'Check if the user entered a valid username and password.


    If objRS.EOF or objRS.BOF Then
            Response.Write "Incorrect Username or password please try again"
        Response.Clear
        Response.Redirect "New112.asp"
    Else
        Response.Write "You have successfuly changed your password"
    End If



'Response.Write " Your passwords has been changed."
'Response.write " The number of record that has changed is: " & _
' intnumofrecord & " records<BR><BR>"

Set objRS = Nothing
objRS.close
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing

%>



</body>
</html>




 
Old March 5th, 2004, 04:13 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

I have found that closing recordsets for an update query often give me that error unless my update is within an if/else or an if/end statement as follows...

rs.open sql, cn
if not rs.eof then
re("Field1") = Field1
re("Field2") = Field2
rs.update
end if
rs.close
set rs = nothing

If I didn't have an if/else or if/end statement I simply would not close the recordset. If that helps you out at all.

 
Old March 5th, 2004, 07:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

An UPDATE query returns a closed recordset if you don't specify explicitly you don't want a recordset (adExecuteNoRecords), so you need to open the Recordset before you can use it in this scenario. However, AFAIK, it won't contain anything useful with an UPDATE statement.

You can take a look at RecordsAffected instead. This will return the number of records affected by the previous query. If it's 0, the UPDATE statement didn't update anything. If it returns 1, your query ran fine. If it returned more than 1, you have a data integrity issue ;)

This page will give you all the nitty gritty details.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Code NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 February 18th, 2008 11:16 PM
Code error reverand Excel VBA 1 November 15th, 2006 02:08 AM
Code error??? emyr BOOK: Beginning Java 2 1 October 31st, 2006 05:47 PM
Code error!?!? Brian Campbell BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 November 26th, 2004 07:47 PM
Error displayed with error trap code stoneman Access 4 February 28th, 2004 02:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.