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:48 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 code for the HTML form (sending the data to the ASP page to be proccessed, 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).

HELP!!!!


//////////////////////HTML Code for Form///////////////////////

<HTML>
<HEAD><TITLE>Genki Dave's Movie Collection - Form</TITLE></HEAD>
<BODY text="#FFFF00" bgcolor="#800000">

<FORM NAME="frmAddMovie" ACTION="http://localhost/add_backup.asp" METHOD="post">

<TABLE BORDER=0>

<TR>
<TH ALIGN="LEFT">Movie Name:</TH>
<TD><INPUT TYPE="textbox" maxLength="20" NAME="txtMovieName" SIZE="25" VALUE="Test Movie"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Genre:</TH>
<TD><SELECT NAME="optGenre">
<OPTION VALUE="0"></OPTION>
<OPTION VALUE="1">Action</OPTION>
<OPTION VALUE="2">Action/Adventure</OPTION>
<OPTION VALUE="3">Adult (XXX)</OPTION>
<OPTION VALUE="4">Animation (Classic Style)</OPTION>
<OPTION VALUE="5">Animation (Modern Style)</OPTION>
<OPTION VALUE="6">Comedy</OPTION>
<OPTION VALUE="7">Drama</OPTION>
<OPTION VALUE="8">Fantasy</OPTION>
<OPTION VALUE="9">Horror</OPTION>
<OPTION VALUE="10">JapanAmation</OPTION>
<OPTION VALUE="11">Martial Arts</OPTION>
<OPTION VALUE="12">Mystery</OPTION>
<OPTION VALUE="13">Romance</OPTION>
<OPTION VALUE="14">Romantic Comedy</OPTION>
<OPTION VALUE="15">Science Fiction</OPTION>
<OPTION VALUE="16">Spy Film</OPTION>
<OPTION VALUE="17">Thriller/Suspense</OPTION>
<OPTION VALUE="18">War</OPTION>
<OPTION VALUE="19">Western</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TH ALIGN="LEFT">Director:</TH>
<TD>
<INPUT TYPE="textbox" maxLength=30 NAME="txTDirector" SIZE="25" VALUE="Dave Andrews"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Year Released:</TH>
<TD>
<INPUT TYPE="textbox" maxLength=20 NAME="txtYearReleased" SIZE="25" VALUE="2004"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Length:</TH>
<TD>
<INPUT TYPE="textbox" maxLength=20 NAME="txtLength" SIZE="25" VALUE="60 mins"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Actor First Name:</TH>
<TD><INPUT TYPE="textbox" maxLength=20 NAME="txtFname" SIZE="25" VALUE="Karen"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Actor Last Name:</TH>
<TD><INPUT TYPE="textbox" maxLength=20 NAME="txtLname" SIZE="25" VALUE="Neugebauer"></TD>
</TR>

<TR>
<TH ALIGN="LEFT">Rating:</TH>
<TD><SELECT NAME="optRating">
<OPTION VALUE="0"></OPTION>
<OPTION VALUE="1">G (General)</OPTION>
<OPTION VALUE="2">PG (Parental Guidance)</OPTION>
<OPTION VALUE="3">PG-13</OPTION>
<OPTION VALUE="4">14A</OPTION>
<OPTION VALUE="5">18A</OPTION>
<OPTION VALUE="6">R (Restricted)</OPTION>
<OPTION VALUE="7">XXX (Adult)</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TH ALIGN="LEFT">Review:</TH>
</TR>
<TR>
<TD COLSPAN="2"><TEXTAREA NAME="txtReview" COLS="35" ROWS="10"></TEXTAREA></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Codec:</TH>
<TD><SELECT NAME="optCodec">
<OPTION VALUE="0"></OPTION>
<OPTION VALUE="1">DivX</OPTION>
<OPTION VALUE="2">XviD</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TH ALIGN="LEFT">CDs:</TH>
<TD>
<INPUT TYPE="textbox" maxLength=20 NAME="txtCDs" SIZE="25" VALUE="1"></TD>
</TR>
<TR>
<TH ALIGN="LEFT">Notes:</TH>
<TD>
<INPUT TYPE="textbox" maxLength=20 NAME="txtNotes" SIZE="25" VALUE="This had better work"></TD>
</TR>

<TR>
</TR>
<TR>
</TR>


<TR>
</TR>
<TR>
<TD ALIGN="middle" COLSPAN="2"><INPUT TYPE="submit" VALUE="Add Record" NAME="btnSubmit"><INPUT TYPE="reset" VALUE="Reset Form" NAME="btnReset"></TD>
</TR>


</TABLE>
</FORM>
</BODY>
</HTML>

///////////////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!!









CodeToad Experts

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








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005