ASP Stored Procedure Operation is not allowed when the object is closed

强颜欢笑 提交于 2019-12-25 05:31:45

问题


I have a problem accessing a Stored Procedure via ASP from an SQL Database. This is my code for the recordset:

Dim com_AntwoordenPerVraag__mem_id
com_AntwoordenPerVraag__mem_id = "0"
If Session("MM_MemberID") <> "" Then
    com_AntwoordenPerVraag__mem_id = Session("MM_MemberID")
End If

Dim com_AntwoordenPerVraag__cat_id
com_AntwoordenPerVraag__cat_id = "0"
If Request.QueryString("cat_id") <> "" Then
    com_AntwoordenPerVraag__cat_id = Request.QueryString("cat_id")
End If

set com_AntwoordenPerVraag = Server.CreateObject("ADODB.Command")
com_AntwoordenPerVraag.ActiveConnection = MM_modular_STRING
com_AntwoordenPerVraag.CommandText = "dbo.spAantal_antwoorden_per_vraag_per_member"
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("@RETURN_VALUE", 3, 4)
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("@mem_id", 3, 1,2,com_AntwoordenPerVraag__mem_id)
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("@cat_id", 3, 1,2,com_AntwoordenPerVraag__cat_id)
com_AntwoordenPerVraag.CommandType = 4
com_AntwoordenPerVraag.CommandTimeout = 0
com_AntwoordenPerVraag.Prepared = true
set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute

rs_AntwoordenPerVraag_numRows = 0

I get the following error message:

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

I get the message here:

If rs_AntwoordenPerVraag.EOF And rs_AntwoordenPerVraag.BOF Then

EDIT

I found the solution.

After:

set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute

I put:

If rs_AntwoordenPerVraag.State <> 1 Then
While rs_AntwoordenPerVraag.State <> 1
Set rs_AntwoordenPerVraag = rs_AntwoordenPerVraag.NextRecordset
Wend
End If

And now it works :-)


回答1:


Your command needs a connection object, and it needs to be opened, rather than just a connection string.

See http://support.microsoft.com/kb/300382

Additionally, your code will be clearer if you import the ADODB constants file, and use those (ie: http://www.4guysfromrolla.com/webtech/faq/Beginner/faq7.shtml )




回答2:


The problem that you have calling the stored procedure is the number of lines touched by each query that is returned by SQL-Server inside a closed recordset before the final resultset. You can either look for the next recordset as you have already found or you can add the following instruction at the beginning of your SP in order to eliminate the sending of the number of lines for each query.

SET NOCOUNT ON

I prefer this last solution as it make the VBScript code simpler but it's just a matter of taste.




回答3:


OP itself have found the solution and it works! Really Thanks to him.

After:

set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute

put:

If rs_AntwoordenPerVraag.State <> 1 Then
While rs_AntwoordenPerVraag.State <> 1
Set rs_AntwoordenPerVraag = rs_AntwoordenPerVraag.NextRecordset
Wend
End If


来源:https://stackoverflow.com/questions/18127018/asp-stored-procedure-operation-is-not-allowed-when-the-object-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!