user186585
user186585

Reputation: 512

can't close recordset in asp&sql server

I keep getting this error:

ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed.

The Asp code i'm using:

    rs.open "usp_reply_insert 132 ,N'abc',N'teeeeeeext',0,N'gest','[email protected]' ",conn
    rs.close

The problem is with the rs.close command

This is the Stored Procedure

    ALTER  PROCEDURE [dbo].[usp_reply_insert]
    @maamar_id int,
    @subject nvarchar(200),
    @text nvarchar(max),
    @userid int,
    @name nvarchar(50),
    @email nvarchar(150)
    AS
    begin

    set nocount on

INSERT INTO dbo.tbl_reply
      (maamar_id,
      userid,
      reply_subject,
      reply_text,
      reply_name,
      reply_email,
      reply_date,
      reply_status
      )
VALUES
      (
      @maamar_id,
      @userid,
      @subject,
      @text,
      @name,
      @email,
      getdate(),
      0
      )



    end

How can I close this recored set?

10x

Upvotes: 0

Views: 449

Answers (2)

Igor Kovalev
Igor Kovalev

Reputation: 1

Your recordset is closed, that's why rs.close method doesn't work. You can use that simple code below to check if a recordset is open or closed (if state=1 it's open, else if state=0 it's closed)

Dim state As Long
state = rs.state
If state <> 0 Then
rs.close
set rs = Nothing
End If

Upvotes: 0

Dan J
Dan J

Reputation: 16708

From the MSDN documentation on the Recordset.Open method:

It is not a good idea to use the Source argument of the Open method to perform an action query that does not return records because there is no easy way to determine whether the call succeeded. The Recordset returned by such a query will be closed.

To perform a query that does not return records, such as a SQL INSERT statement, call the Execute method of a Command object or the Execute method of a Connection object instead.

In short, your rs.open call is not resulting in an open recordset, so the rs.close statement doesn't function and should be removed. Better yet, follow the example given in the quoted text, as using ADODB.Recordset to invoke an INSERT op is not recommended.

Upvotes: 4

Related Questions