codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Argh!! - Operation is not allowed when the object is closed.  GenkiDave at 08:58 on Sunday, January 25, 2004
 

OK, so I see that there are quite a few people here that have the same error as I, but I can't seem to see where the error starts or ends, or whatever...

Anyway, I get this specific error:

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


Line 39 is this: rsAddMovie.AddNew

I wish I new where are good debugger was for ASP and SQL like Visual Basic, where I could insert a break point and SEE the error occur with my own eyes, and therefore know what to fix.

Anyway, below is the ASP code from the HTML form then after, redirect to a page that shows all the data I wish to see in the MS Access Database, which is only 2 records (manually inserted).
Don't comment on the missing delimiters, I took them out for this Thread.

HELP!!!!

///////////////ASP Code to process from HTML Form///////////////


'Dimension variables
Dim conn 'Holds the Database Connection Object
Dim rsAddMovie 'Holds the recordset for the new record to be added
Dim strSQL 'Holds the SQL query to query the database

'Create an ADO connection object
Set conn = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
conn.Open "DSN=movie"

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

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "INSERT INTO tblMovies (MovieName, GenreID, Director, YearReleased, Length, RatingID, Review, CodecID, CDs, Notes) VALUES ('" & request.form("txtMovieName") & "'," & request.form("optGenre") & ",'" & request.form("txtDirector") & "','" & request.form("txtYearReleased") & "','" & request.form("txtLength") & "'," & request.form("optRating") & ",'" & request.form("txtReview") & "'," & request.form("optCodec") & ",'" & request.form("txtCds") & "','" & request.form("txtNotes") & "')"
strSQL = "INSERT INTO tblActors (Fname, Lname) VALUES ('" & request.form("txtFname") & "','" & request.form("txtLname") & "')"
conn.Execute (strSQL)


'Set the cursor type we are using so we can navigate through the recordset
rsAddMovie.CursorType = 2


'Set the lock type so that the record is locked by ADO when it is updated
rsAddMovie.LockType = 3



'Open the recordset with the SQL query
rsAddMovie.Open strSQL, conn



'Tell the recordset we are adding a new record to it
rsAddMovie.AddNew

'Add a new record to the recordset
rsAddMovie.Fields("MovieName") = Request.Form("txtMovieName")
rsAddMovie.Fields("GenreID") = Request.Form("optGenre")
rsAddMovie.Fields("Director") = Request.Form("txtDirector")
rsAddMovie.Fields("YearReleased") = Request.Form("txtYearReleased")
rsAddMovie.Fields("Length") = Request.Form("txtLength")
rsAddMovie.Fields("RatingID") = Request.Form("optRating")
rsAddMovie.Fields("Review") = Request.Form("txtReview")
rsAddMovie.Fields("CodecID") = Request.Form("optCodec")
rsAddMovie.Fields("CDs") = Request.Form("txtCds")
rsAddMovie.Fields("Notes") = Request.Form("txtNotes")
rsAddMovie.Fields("Fname") = Request.Form("txtFname")
rsAddMovie.Fields("Lname") = Request.Form("txtLname")

'Write the updated recordset to the database
rsAddMovie.Update

'Reset server objects
rsAddMovie.Close
Set rsAddMovie = Nothing
Set conn = Nothing

'Redirect to the movie.asp page
Response.Redirect "http://localhost/movie.asp"


An easy, understandable, Down to Earth explanation and fix would be greatly appreciated. Thanks!!


  Re: Argh!! - Operation is not allowed when the object is closed.  joriz at 00:28 on Wednesday, January 28, 2004
 


instead of this

conn.Execute (strSQL)

try

set rsAddMovie = conn.Execute (strSQL)


Also your first value assignment in strSQL did not actually do anything at all since your next line immediately overwrites the value stored in strSQL









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007