|
 |
asp_databases thread: Operation is not allowed when the object is closed. HELP!!
Message #1 by "adam stawski" <shokempo@h...> on Thu, 24 May 2001 03:29:34
|
|
Hello,
I am an ASP newbie and have a problem when inserting records into an
Access 2000 database. I use II5 on my W2K workstation.
OK...here is the code for you gurus ;) Pretty simple!
My error msg is this...
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/regform1.asp, line 52
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add records.</title>
</head>
<body>
<form method="post" action="regform.asp">
<table align="center" width="286">
<tr>
<td width="89">Username:</td>
<td width="185"><input type="text" name="uname" value=""
size="32"></td></tr>
<td> </td>
<td> <input type="submit" name="Submit"
value="Submit"></td></tr>
</table>
</form>
<!-- #INCLUDE FILE="adovbs.inc" -->
<%
' Declare my variables
Dim strUsername
Dim Conn ' As ADODB.Connection
Dim objRS
Dim strSQL
strUsername = Request.Form("uname")
Set Conn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "INSERT INTO details (username) VALUES ('"& strUsername & "')"
'testpool is my system DSN
Conn.Open "DSN=regform"
objRS.open strSQL, Conn, adOpenKeyset, adLockOptimistic
objRS.AddNew <-------This is line 52.
objRS.Update
objRS.Close
Set objRS = Nothing
Conn.Close
Set Conn = Nothing
%>
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 24 May 2001 17:15:44 +1000
|
|
argh - this was on the list *yesterday*
An INSERT SQL statement does not return any records. Since you are not
returning any records, you do not have a recordset. Since you do not have a
recordset you can't do:
objRS.Addnew
What you want to do instead is:
(ditch the SQL statement line)
objRS.open "tableNameHere", objConn, adOpenForwardOnly, adLockOptimistic,
adCmdTable
objRS.AddNew
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "adam stawski" <shokempo@h...>
To: "ASP Databases" <asp_databases@p...>
Sent: Thursday, May 24, 2001 3:29 AM
Subject: [asp_databases] Operation is not allowed when the object is closed.
HELP!!
: Hello,
: I am an ASP newbie and have a problem when inserting records into an
: Access 2000 database. I use II5 on my W2K workstation.
:
: OK...here is the code for you gurus ;) Pretty simple!
:
: My error msg is this...
:
: Error Type:
: ADODB.Recordset (0x800A0E78)
: Operation is not allowed when the object is closed.
: /regform1.asp, line 52
:
:
: <%@ LANGUAGE="VBSCRIPT" %>
: <% Option Explicit %>
:
Message #3 by "Charles Feduke" <webmaster@r...> on Thu, 24 May 2001 08:23:51 -0400
|
|
> Error Type:
> ADODB.Recordset (0x800A0E78)
> Operation is not allowed when the object is closed.
> /regform1.asp, line 52
> objRS.AddNew <-------This is line 52.
The whole caveat of using an INSERT statement is that it is a command that
DOES something, *not* a recordset that returns something. Had your SQL
string been a "SELECT * FROM table"-like statement, you would use a
recordset. However, as you are actually using an INSERT statement, you need
only to have the server execute it, like so:
Conn.Execute strSQL, , adExecuteNoRecords
Connection objects can execute SQL statements that do not return
recordsets, and they return recordsets for SELECT statements (i.e. Set
rsData = conConnection.Execute strSQL); when a connection object returns a
recordset it is always firehose flavor (that is, adOpenForwardOnly).
? Chuck
> -----Original Message-----
> From: adam stawski [mailto:shokempo@h...]
> Sent: Thursday, May 24, 2001 3:30 AM
> To: ASP Databases
> Subject: [asp_databases] Operation is not allowed when the object is
> closed. HELP!!
>
>
> Hello,
> I am an ASP newbie and have a problem when inserting records into an
> Access 2000 database. I use II5 on my W2K workstation.
>
> OK...here is the code for you gurus ;) Pretty simple!
>
> My error msg is this...
>
> Error Type:
> ADODB.Recordset (0x800A0E78)
> Operation is not allowed when the object is closed.
> /regform1.asp, line 52
>
>
> <%@ LANGUAGE="VBSCRIPT" %>
> <% Option Explicit %>
>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <title>Add records.</title>
> </head>
> <body>
> <form method="post" action="regform.asp">
>
> <table align="center" width="286">
> <tr>
> <td width="89">Username:</td>
> <td width="185"><input type="text" name="uname" value=""
> size="32"></td></tr>
> <td> </td>
> <td> <input type="submit" name="Submit"
> value="Submit"></td></tr>
> </table>
>
> </form>
>
> <!-- #INCLUDE FILE="adovbs.inc" -->
>
> <%
> ' Declare my variables
>
> Dim strUsername
>
> Dim Conn ' As ADODB.Connection
> Dim objRS
> Dim strSQL
>
> strUsername = Request.Form("uname")
>
>
> Set Conn = Server.CreateObject("ADODB.Connection")
>
> Set objRS = Server.CreateObject("ADODB.Recordset")
>
>
> strSQL = "INSERT INTO details (username) VALUES ('"& strUsername & "')"
>
> 'testpool is my system DSN
> Conn.Open "DSN=regform"
>
> objRS.open strSQL, Conn, adOpenKeyset, adLockOptimistic
>
> objRS.AddNew <-------This is line 52.
> objRS.Update
> objRS.Close
> Set objRS = Nothing
>
> Conn.Close
> Set Conn = Nothing
>
> %>
|
|
 |