ADODB.Recordset 错误 '800a0e78' - 当我传递 2 个参数时出错 (ASP/MSSQL)

发布于 2025-01-06 07:26:05 字数 1574 浏览 1 评论 0原文

当我将 2 个参数传递给我的 Exec 代码时,我的经典 ASP 页面出现错误 存储过程。基本上我想发送 1 个参数来覆盖我正在寻找的列 一个用于搜索词。例如纽约大学 imSchool。我对发送的数据以及记录集进行了数据检查。状态代码显示,每次我选择带有两个参数的 SQL 查询时,都会出现错误“对象关闭时不允许操作”。总是显示。 我尝试在“While Not rs.EOF”代码行打开该对象,但它出错了,但运气不佳。 我认为我的 SQLQuery 很糟糕,因为当我使用相同的输入在 MSSQL 中运行存储过程时,我每次都会得到一个返回表。 SQL Server 2008 R2 和经典 ASP。

这是我的带有 SQLQUERY 代码的 IF 语句(请记住第一个工作正常,并且数据是从数据库中选择的)

    SQLQuery = "Exec sp_vw_InternImport"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorType = 3

    rs.Open SQLQuery, OBJdbConnection


    If filterColmn <> "" Then

    SQlQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorType = 3

    rs.Open SQLQuery, OBJdbConnection

    End If

这是我的存储过程代码

          SET ANSI_NULLS ON
            GO
            SET QUOTED_IDENTIFIER ON
             GO

           ALTER PROCEDURE [dbo].[sp_vw_InternImport_ColID]
            (
            @LookUpID nvarchar (255),
            @LookUpCol nvarchar (50)
            )

          AS 
       SET NOCOUNT ON
       BEGIN 

        IF @LookUpCol = 'imYear'
        SELECT * FROM v_InternImport WHERE imYear = @LookUpID

ELSE
IF @LookUpCol = 'imSchool'
SELECT * FROM v_InternImport WHERE imSchool = @LookUpID

ELSE
IF @LookUpCol = 'imDiscipline'
SELECT * FROM v_InternImport WHERE imDiscipline = @LookUpID

       IF @LookUpCol = 'imDegree'
       SELECT * FROM v_InternImport WHERE imDegree = @LookUpID
       END

My classic ASP page thorws up an error when I pass 2 paremeters to the Exec code for my
stored procedure. Basically I want to send 1 paremeter to cover the column I am looking for
and one for the search-term. For example imSchool, New York University. I have data checks on the data sent as well as Record Set.State code showing that everytime i choose SQL Query with the two paramerts the error "Operation is not allowed when the object is closed." always shows.
I tried to open the object at " While Not rs.EOF" line of code where it error out bit no luck.
I am thinking my SQLQuery is bad because when I run the Stored Procedure in MSSQL with the same input I get a return table everytime. SQL Server 2008 R2 and Classic ASP.

HERE IS MY IF STATMENT WITH SQLQUERY CODE (keep in mind the 1st one works fine and data is selected from the DB)

    SQLQuery = "Exec sp_vw_InternImport"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorType = 3

    rs.Open SQLQuery, OBJdbConnection


    If filterColmn <> "" Then

    SQlQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorType = 3

    rs.Open SQLQuery, OBJdbConnection

    End If

HERE IS MY STORED PROCEDURE CODE

          SET ANSI_NULLS ON
            GO
            SET QUOTED_IDENTIFIER ON
             GO

           ALTER PROCEDURE [dbo].[sp_vw_InternImport_ColID]
            (
            @LookUpID nvarchar (255),
            @LookUpCol nvarchar (50)
            )

          AS 
       SET NOCOUNT ON
       BEGIN 

        IF @LookUpCol = 'imYear'
        SELECT * FROM v_InternImport WHERE imYear = @LookUpID

ELSE
IF @LookUpCol = 'imSchool'
SELECT * FROM v_InternImport WHERE imSchool = @LookUpID

ELSE
IF @LookUpCol = 'imDiscipline'
SELECT * FROM v_InternImport WHERE imDiscipline = @LookUpID

       IF @LookUpCol = 'imDegree'
       SELECT * FROM v_InternImport WHERE imDegree = @LookUpID
       END

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2025-01-13 07:26:05

直接将参数传递给存储过程时,不必“分配”参数。这样做可能会导致传递整个值(例如,@LookUpCol 将具有 @LookUpCol ='imYear' 的值),因此您的 SP 不会选择任何内容,并且您有空且关闭的记录集。

尝试使用这样的代码:

SQlQuery = "Exec sp_vw_InternImport_ColID '" & filterID & "', '" & filterID & "'"

When passing arguments to stored procedure directly, you don't have to "assign" the parameters. Doing this probably results in the whole value passed (e.g. @LookUpCol will have the value of @LookUpCol ='imYear') thus your SP won't select anything and you have empty and closed recordset.

Try having such code instead:

SQlQuery = "Exec sp_vw_InternImport_ColID '" & filterID & "', '" & filterID & "'"
心头的小情儿 2025-01-13 07:26:05

您不能同时使用同一个对象两次(例如 rs),您必须将其命名为另一个名称,或者必须关闭它并重新开始。这应该有效:

SQLQuery = "Exec sp_vw_InternImport"
If filterColmn <> "" Then SQLQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

  Set rs = Server.CreateObject("ADODB.Recordset")
  rs.CursorType = 3
  rs.Open SQLQuery, OBJdbConnection
  rs.Close

或者在您的例如,如果您在继续下一个对象之前关闭第一个 rs 对象,这可能会有所帮助。

set rs = Nothing ...然后...set rs = server.createobject

像这样:

SQLQuery = "Exec sp_vw_InternImport"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = 3
rs.Open SQLQuery, OBJdbConnection

rs.Close ------ Close it before you re-open it

If filterColmn <> "" Then

SQlQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

rs.Open SQLQuery, OBJdbConnection
rs.Close ------ Always Close your Objects!

End If

You can't use the same object twice at the same time (like rs), you have to make it another name or you have to close it and start over.. This should work:

SQLQuery = "Exec sp_vw_InternImport"
If filterColmn <> "" Then SQLQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

  Set rs = Server.CreateObject("ADODB.Recordset")
  rs.CursorType = 3
  rs.Open SQLQuery, OBJdbConnection
  rs.Close

Or in your example, if you close the first rs object before you go on to the next, it may help.

set rs = nothing ... then .... set rs = server.createobject

So like this:

SQLQuery = "Exec sp_vw_InternImport"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = 3
rs.Open SQLQuery, OBJdbConnection

rs.Close ------ Close it before you re-open it

If filterColmn <> "" Then

SQlQuery = "Exec sp_vw_InternImport_ColID @LookUpID=N'" + filterID + "'" + ", @LookUpCol=N'" + filterID + "'"

rs.Open SQLQuery, OBJdbConnection
rs.Close ------ Always Close your Objects!

End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文